[Solved] Add controls to a StackPanel in a BackgroundWorker or async Task called from another BackgroundWorker

You cannot create controls from any thread except for the UI thread. To run code on the UI thread you can use Dispatcher.BeginInvoke, you can find the dispatcher on any UI element (in the Dispatcher property) or using the statis Dispatcher.CurrentDispatcher property from the UI thread before starting the background process. solved Add controls to … Read more

[Solved] Use Enum values as Properties in

I’m not sure what is your question, but as @crashmstr commented .. it seems you don’t need an Enum but you just need a class to hold these properties Any way you can use this BUT IT’S NOT A GOOD PRACTICE and I don’t know what do you want the setter to do public string … Read more

[Solved] how to write an user control for WPF XAML [duplicate]

I would use a Custom Control and not a User Control and make the default child a custom DependencyProperty and add to the control’s content manually [ContentProperty(“ConditionalContent”)] public partial class If : ContentControl { public If() { Loaded += OnLoad; } private void OnLoad(object sender, RoutedEventArgs e) { update(); } private void update() { Content … Read more

[Solved] How can I use combobox with wpf mvvm

Your code in LocationFilter make no sense at all. ParticularEntries.Select(pg => pg.Region.Location == _selectedLocation); It returns an IEnumerable<bool> but it is never assigned. If you want to filter, you have to use Where. But even if you change your code to ParticularEntries = ParticularEntries.Where(pg => pg.Region.Location == _selectedLocation); you will see a change, but you … Read more

[Solved] Set datagrid row background color WPF – Loop [closed]

I resolved this problem. So the problem is because I fill DataGrid again with Data. Instead that I don’t fill it I only get ID where I stopped from last time in that Table with some ID. Code for Button Continue: int postID; string fbGroupID; int listID = int.Parse(cmbSelectList.SelectedValue.ToString()); using (OleDbConnection connection = new OleDbConnection(conn)) … Read more

[Solved] Creating abstract ViewModels wpf

Ok, I found the glitch. Int the MainViewModel class, the TestViewModel property should be changed from: public IViewModel TestViewModel { get { return m_testViewModel; } set { m_testViewModel = value; OnPropertyChanged(“NewViewModel”); } } To: public IViewModel TestViewModel { get { return m_testViewModel; } set { m_testViewModel = value; OnPropertyChanged(“TestViewModel”); } } solved Creating abstract ViewModels … Read more

[Solved] How to convert a string to formatted text C# [closed]

You can always use the normal C# tools to do this. However, if the entire purpose is to make a nice string for binding, you may be able to use the binding’s StringFormat directly. For example, you can have a TextBlock like so: <TextBlock> <TextBlock.Text> <MultiBinding StringFormat=”{}{0} at distance of {1}m.”> <Binding Path=”User”/> <Binding Path=”Distance”/> … Read more

[Solved] binding an List of objects to a Listbox

The Error you are getting is probably: Items collection must be empty before using ItemsSource. There is probably no problem with binding…. your bigest problem is invalid xaml. I am not sure what you are trying to achieve, but I guess you want to have listbox with horizonatal Stackpanel as ItemsPanel. Then it should be … Read more

[Solved] About ListBox limit item [closed]

From your question, it looks like you need to implement virtualization on the listbox. You can either use a VirtualizingStackPanel inside a Listbox as ItemsPanel Template or you use – ItemsControl and set its property VirtualizingStackPanel.IsVirtualizing=”True” This should help. solved About ListBox limit item [closed]