r/stackoverflow • • Sep 03 '24

Question [C#][WPF] Looking for the actual reason why I cannot bind DataGridTemplateColumn Foreground attribute to interface property.

1 Upvotes

I've tried many things, non of which solve the problem while retaining the full DataGrid functionality, most importantly the ability to edit a cell.

I'm pretty much resigned to the fact that It simply doesn't work, because I'm not really committed to it. I am however stuck in the frustration loop thinking about it, which I hoped abandoning the idea would negate. Alas, it has not.

I just don't get it, and can't find a solid reason why.

All other attributes bind to the assigned properties of the interface.

Relevant code:

MainWindow:

public ObservableCollection<IPathInfo> InfoList { get; set; } = new();

DataGrid ItemsSource is bound to this property.

EDIT: Nailed it, can finally get some work done,

<DataGridTextColumn
    Binding="{Binding Name}"
    Header="Name"
    IsReadOnly="False">
    <DataGridTextColumn.CellStyle>
        <Style TargetType="{x:Type DataGridCell}">
            <Setter Property="Foreground" Value="{Binding Path=(local:IPathInfo.ForeColor)}"/>
        </Style>
    </DataGridTextColumn.CellStyle>
    <!--<TextBlock.Foreground>
        <SolidColorBrush Color="{Binding Path=(local:IPathInfo.ForeColor)}" />
    </TextBlock.Foreground>-->
</DataGridTextColumn>

XAML:

<DataGridTextColumn
    Binding="{Binding Name}"
    Foreground="{Binding ForeColor}"
    Header="Name"
    IsReadOnly="False" />

If I bind the Foreground attribute to a property of MainWindow named ForeColor, it works as I would expect. But that negates its intended functionality.

Interface:

public interface IPathInfo
{
    string Name { get; set; }
    ImageSource FileIcon { get; set; }
    long Length { get; set; }
    Brush ForeColor { get; set; }
}

Class:

public class MyFileInfo : IPathInfo
{
    public string Name { get; set; }
    public ImageSource FileIcon { get; set; }
    public long Length { get; set; } = 0;
    public Brush ForeColor { get; set; } = Brushes.Yellow;

    public MyFileInfo(string name)
    {
        Name = name;
    }
}

This is one of two classes implementing the interface, the other sets a different color brush.


r/stackoverflow • • Sep 02 '24

Other code Golfing a Native Messaging host with tee command

Thumbnail
gist.github.com
1 Upvotes

r/stackoverflow • • Sep 02 '24

Python Bulk apply time.sleep(seconds)? In Python?

1 Upvotes

I’m writing a long questionnaire program for my resume, is there a way for me to make it so every single print statement/input in my main module as well as my functions will be preceded and followed by time.sleep(seconds) with a singular function or a few lines of code, rather than having to manually enter it between each line?


r/stackoverflow • • Sep 01 '24

Question Phasmophobia game light flickering

1 Upvotes

Hey guys, my friend and want to program a python script that makes your IRL Light flicker when the ghost is hunting, is there an API that gives kind of information when the ghost is hunting or anything other? Any Information to this is helpful! Thank you!


r/stackoverflow • • Aug 30 '24

Python Use machine learning model to predict stock prices

1 Upvotes

Hi everyone,

I'm a beginner in Machine Learning, and as a small project, I would like to try and predict stock prices. I know the stock market is basically a random process and therefore I don't expect any positive returns. I've build a small script that uses a Random Forest Regressor that has been trained on AAPL stock data from the past 20 years or so, except for the last 100 days. I've used the last 100 days as validation.

Based on the open/close/high/low price and the volume, i have made two other columns in my dataframe: the increase/decrease of closing price in percentage and a days_since_start_column as the model can't learn on datetime if I'm correct.

Anyway, this is the rest of the code:

df = pd.read_csv('stock_data.csv')
df = df[::-1].reset_index()
df['timestamp'] = pd.to_datetime(df['timestamp'])
df['% Difference'] = df['close'].pct_change()

splits = [
    {'date': '2020-08-31', 'ratio': 4},
    {'date': '2014-06-09', 'ratio': 7},
    {'date': '2005-02-28', 'ratio': 2},
    {'date': '2000-06-21', 'ratio': 2}
]

for split in splits:
    split['date'] = pd.to_datetime(split['date'])
    split_date = split['date']
    ratio = split['ratio']
    df.loc[df['timestamp'] < split_date, 'close'] /= ratio

df['days_since_start'] = (df['timestamp'] - df['timestamp'].min()).dt.days
#data = r.json()
target = df.close
features = ['days_since_start','open','high','low','volume']

X_train = (df[features][:-100])
X_validation = df[features][-100:]

y_train = df['close'][:-100]
y_validation = df['close'][-100:]

#X_train,X_validation,y_train,y_validation = train_test_split(df[features][:-100],target[:-100],random_state=0)


model = RandomForestRegressor()
model.fit(X_train,y_train)
predictions = model.predict(X_validation)

predictions_df = pd.DataFrame(columns=['days_since_start','close'])
predictions_df['close'] = predictions
predictions_df['days_since_start'] = df['timestamp'][-100:].values
plt.xlabel('Date')
#plt.scatter(df.loc[X_validation.index, 'timestamp'], predictions, color='red', label='Predicted Close Price', alpha=0.6)
plt.plot(df.timestamp[:-100],df.close[:-100],color='black')
plt.plot(df.timestamp[-100:],df.close[-100:],color='green')
plt.plot(predictions_df.days_since_start,predictions_df.close,color='red')
plt.show()

I plotted the closing stock price of the past years up untill the last 100 days in black, the closing price of the last 100 days in green and the predicted closing price for the last 100 days in red. This is the result (last 100 days):

Why does the model stay flat after the sharp price increase? Did I do something wrong in the training process, is my validation dataset too small or is it just a matter of hyperparameter tuning?

I'm still very new to this topic, so love to learn from you!


r/stackoverflow • • Aug 28 '24

Python Specify desired file download location for API pulls?

1 Upvotes

The title makes my code look more complex than it actually is.

https://pastebin.com/j5ii1Bes

I got it working, but it sends the photo to the same location the .py file is located. How can I either tell the code to send it to a specific destination on Windows, enable user input to ask, or trigger the windows file download prompt?


r/stackoverflow • • Apr 04 '20

Please support my site proposal for Vexillology

1 Upvotes

r/stackoverflow • • Mar 24 '20

i get question banned after 7 years participating in stackoverflow. is my question really so stupid?

Thumbnail
stackoverflow.com
1 Upvotes

r/stackoverflow • • Mar 23 '20

Does anybody actually LIKE to use SO?

1 Upvotes

It seems like a lot of confrontation and/or conflict happens around here, specifically to the detriment of new users who ask questions some would consider to be “noob-like” or something along those lines and continue to send a link to what may as well be the first search result on Google.

Is this how people feel?


r/stackoverflow • • Feb 28 '20

How do you log out from stack overflow?

1 Upvotes

Can't find a logout button and clicking on the logo in the top left corner didn't help.


r/stackoverflow • • Jan 17 '20

Can someone help me with this problem for otp generation

1 Upvotes

I'm a newbie working on my first project. If any of you guys can help it would be appreciated.

https://stackoverflow.com/questions/59703884/otp-one-time-password-function-not-working-in-c-sharp


r/stackoverflow • • Jan 09 '20

New to Using APIs. Really dumb question. Does the key allow me to use whatever door I want?

1 Upvotes

So there’s a website that has endpoints for Python, RUBY, and cURL. I have token for those and I have been able to do what I need to do.

I want to run it 24/7, but don’t wanna buy a server. Google apps script seems to be a good solution. Would I be able to translate my code to apps script or another language even though there’s no endpoint specified.

Does the key allow me to use whatever door I want?


r/stackoverflow • • Jan 03 '20

Need help formatting my question

1 Upvotes

I am trying to make a post on Stack Overflow but I am not very good at formatting questions. I tried to explain it thoroughly but I think I didn't do it well enough. Hopefully someone here can better explain where I went wrong or can ask my questions here so that I don't get banned on there. I am not trying to waste people's time I just want to get help on a project. I don't need people to do it for me either I just need basic help with syntax. I put the post here:

"

I am working on a project using a Parallax Laser RangeFinder ([datasheet][1]) and I am using a Raspberry Pi 3 Model B+ to control it.

Because I am using a Raspberry Pi, I am having to use Python to control it, specifically, the serial communication on the Pi. I have tried to program this myself by researching serial communication on the Pi to no avail. I have found an example of this exact device being used but on an Arduino and subsequently, using C code. I was wondering if there was an easier way that I hadn't seen to convert from C++ to Python easily using the example [here][2].

My main objective is to find the syntax needed to recreate the sending/receiving of the data from the Pi to the device. The code provided isn't exactly what I need but it gives an understanding of what types of syntax the device uses. For example, it requires a user to send a "U" to check if the device is ready, I am primarily trying to find the syntax on how to do that in Python.

I have also included the exact code from the section I am trying to replicate below:

```

#include <SoftwareSerial.h>

#define rxPin 8 // Serial input (connects to the LRF's SOUT pin)

#define txPin 9 // Serial output (connects to the LRF's SIN pin)

#define ledPin 13 // Most Arduino boards have an on-board LED on this pin

#define BUFSIZE 16 // Size of buffer

int lrfDataInt;

SoftwareSerial lrfSerial = SoftwareSerial(rxPin, txPin);

void setup() // Set up code called once on start-up

{

// *************************************** setup for LRF ***********************************************

pinMode(ledPin, OUTPUT);

pinMode(rxPin, INPUT);

pinMode(txPin, OUTPUT);

digitalWrite(ledPin, LOW); // turn LED off

Serial.begin(9600);

while (!Serial); // Wait until ready

Serial.println("\n\nParallax Laser Range Finder");

lrfSerial.begin(9600);

Serial.print("Waiting for the LRF...");

delay(2000); // Delay to let LRF module start up

lrfSerial.print('U'); // Send character

while (lrfSerial.read() != ':');

delay(10); // Short delay

lrfSerial.flush(); // Flush the receive buffer

Serial.println("Ready!");

Serial.flush(); // Wait for all bytes to be transmitted to the Serial Monitor

}

// ****************************************** main loop ************************************************

void loop() // Main code, to run repeatedly

{

lrf();

}

// ****************************************** end main loop *********************************************

void lrf()

{

lrfSerial.print('R'); // Send command

digitalWrite(ledPin, HIGH); // Turn LED on while LRF is taking a measurement

char lrfData[BUFSIZE]; // Buffer for incoming data

int lrfDataInt1;

int lrfDataInt2;

int lrfDataInt3;

int lrfDataInt4;

int offset = 0; // Offset into buffer

lrfData[0] = 0; // Clear the buffer

while(1)

{

if (lrfSerial.available() > 0) // If there are any bytes available to read, then the LRF must have responded

{

lrfData[offset] = lrfSerial.read(); // Get the byte and store it in our buffer

if (lrfData[offset] == ':') // If a ":" character is received, all data has been sent and the LRF is ready to accept the next command

{ lrfData[offset] = 0; // Null terminate the string of bytes we just received

break; } // Break out of the loop

offset++; // Increment offset into array

if (offset >= BUFSIZE) offset = 0; // If the incoming data string is longer than our buffer, wrap around to avoid going out-of-bounds

}

}

lrfDataInt1 = ( lrfData[5] -'0');

lrfDataInt2 = ( lrfData[6] -'0');

lrfDataInt3 = ( lrfData[7] -'0');

lrfDataInt4 = ( lrfData[8] -'0');

lrfDataInt = (1000*lrfDataInt1)+ (100*lrfDataInt2)+(10*lrfDataInt3) + lrfDataInt4;

Serial.print("Distance = "); // The lrfData string should now contain the data returned by the LRF, so display it on the Serial Monitor

Serial.println(lrfDataInt);

Serial.flush(); // Wait for all bytes to be transmitted to the Serial Monitor

digitalWrite(ledPin, LOW); // Turn LED off

delay(1000);

} ```

[1]: https://www.parallax.com/sites/default/files/downloads/28044-Laser-Range-Finder-Guide-v2.0.pdf

[2]: https://www.deviceplus.com/how-tos/arduino-guide/make-a-laser-arduino-robot-using-parallax-laser-sensor-part-2/

"


r/stackoverflow • • Dec 23 '19

What do i do?

1 Upvotes

Hi all.

I get this when trying to post a question, what do i do?

here My Account/Profile


r/stackoverflow • • Nov 22 '19

Building Open Source Stack for Managing and Deploying ML Models To Analyze StackOverflow Posts

1 Upvotes

The following tutorial is using a couple of open-source tools (DVC and Cortex) to create a model capable of analyzing StackOverflow posts, and recognizing which ones are about Python: An Open Source Stack for Managing and Deploying Models


r/stackoverflow • • Oct 10 '19

Looking for stack Overflow iOS client app

1 Upvotes

I’ve just created an account in stackoverflow and started using it a day ago. And it is very tedious to use their site in mobile browser. Is there any iOS client app available for stackoverflow?

PS:- I tried installing StackExchange app in App Store. It didn’t help. It wasn’t even opened and crashed whenever I tried opening it.


r/stackoverflow • • Oct 06 '19

Is it intended for The Overflow newsletter to be auto opt-in?

Thumbnail
meta.stackoverflow.com
1 Upvotes

r/stackoverflow • • Oct 06 '19

Flutter, Calling a method from build?

1 Upvotes

So i am creating an app that uses a streambuilder that pulls data from firebase and updates multiple devices with this method. Everytime my firebase list changes it calls streambuilder and updates everyones phones. Now I am trying to call a method for a specific user when another user changes the firebase data. When this user changes the data it will call streambuilder on the others phone and this is when i need to call that method. I cant do anything outside of the build to call functions because the other users screen only updates inside that stream call when the 2nd user changes the stream data (firebase). SO my questions are: How can i call a function while building? Can i display a notification while building? Can you recommend a better method for me to use rather then having to try and work while building? Thank you


r/stackoverflow • • Sep 11 '19

About down voting on the site

1 Upvotes

If you ask a question that another user may find too simple or wrong in a sense, why downvote? Obviously, if you are asking a question, you need help. Don't downvote if it's wrong. There's a reason the question was asked to begin with. At least answer and say why you want to downvote.


r/stackoverflow • • Aug 29 '19

Easy indexOf problem. Help!!

1 Upvotes

Hi guys, I'm new to the sub, and I need help with a very easy problem. I am currently in a programming 'bootcamp'. If anyone can answer this. Thank you. If anyone can explain it to me. Thanks again. Also I have to use indexOf to solve this, no filter.

Write a function unique(array) that returns an array where all the duplicates

of the input array have been removed; in other words, every element remaining

is unique.

Hint: use indexOf

Example:

unique([1, 1, 2, 3, 3]) => [1, 2, 3]


r/stackoverflow • • Aug 25 '19

CSS to ASCII converter wanted

Post image
1 Upvotes

r/stackoverflow • • Jul 31 '19

Can you use Stack Overflow during coding interviews?

Thumbnail
youtu.be
1 Upvotes

r/stackoverflow • • Jul 30 '19

Need help. Program supposed to count how many characters are in name but it is refusing to enter the if statement

Post image
1 Upvotes

r/stackoverflow • • Jun 29 '19

I can't pull up tags

1 Upvotes

Is anyone else having this problem? I can't pull up tags. I can't submit anything cause I can't tag it. Nothing happens I type things in and it's just text. I can't click next. I tried another browser and it doesn't work there either. Is my account blocked or something? No one else seems to be having to issue I haven't been able to find any trouble shooting information on it.

Edit: I have posted question on stack overflow before and usually when typing things just pull up. Has there been a change? I have tried a few keys after typing things (enter, tab, ctrl, I don't know) it just doesn't turn into a tag.


r/stackoverflow • • Jun 01 '19

We are in 2019 and the holy Stackoverflow is unwelcome more than ever

1 Upvotes

Sadly that's true, this site made by all users, even users with less than 15 rep. but now site managed by some high rep users, which some of them earned their scores unfair (based on SO's rules). (I can prove it)

When some user post something on Meta about that, they attacked to kill him, first downvotes and then delete the post, I don't know if we can not discuss SO on Meta, where can we?!

They deleted low rep user's post immediately, but high rep users can even post/ask duplicates, post their answers on multiple questions, you name it.

There are rules on Stackoverflow, but sadly doesn't apply equally to everyone.

Edit

There is many obvious duplicate questions that is not marked as duplicate and almost all of them asked by high rep users, but some like this as mentioned by alpha-201 marked as duplicate (yes, maybe that's duplicate, but there are many more obvious duplicates which doesn't marked as duplicate, and I don't this any reason but the user rep) and is this fair to you?!