Posts

Showing posts with the label wpf

WPF C# DataTrigger Binding to OnPropertyChanged

WPF C# DataTrigger Binding to OnPropertyChanged I'm trying to create a DataTrigger which changes the style of a border whenever a certain property is changed. I've created the property and I'm calling the PropertyChanged event and it works perfectly fine with other XAML components, but for some reason, it won't work with my DataTrigger. XAML File: <Style x:Key="InputParameterBorder" TargetType="Border" BasedOn="{StaticResource ParameterBorder}"> <Setter Property="Background" Value="{StaticResource GrayGradient}"/> <Style.Triggers> <!-- This changes input color --> <DataTrigger Binding="{Binding Parameter, Converter={StaticResource IsNullConverter}}" Value="False"> <Setter Property="Background" Value="{StaticResource YellowGradient}" /> </DataTrigger> </Style.Trig...

WPF: How to data bind a ComboBox to ListView selection and set the ComboBox value range?

WPF: How to data bind a ComboBox to ListView selection and set the ComboBox value range? I'm new in WPF land and have the following question regarding data binding. My test app contains a ListView with cars (Colums: Type, Speed and Color). Below the list view there are some controls to control the selected car's values. Among others there's a ComboBox to choose the selected car's color. My test app looks like this In XAML the ListView is initialized like this: <ListView Grid.Row="1" Name="listView" ItemsSource="{Binding Model.Cars}" SelectedValue="{Binding Model.SelectedCar}"> <ListView.View> <GridView> <GridView.Columns> <GridViewColumn Header="Type" Width="Auto" DisplayMemberBinding="{Binding Name}" /> <GridViewColumn Header="Speed" Width="Auto" DisplayMemberBinding="{Binding Speed}" /> <Gri...

WPF UserControl DependencyProperty use in XAML or by binding

Image
WPF UserControl DependencyProperty use in XAML or by binding I want a universal UserControl where i can set a property either by setting its value in XAML directly or by binding it to some model property. Just like TextBlock Text property works. Right now i just have the bare simple UserControl, it has a single DependencyProperty TxT and a TextBlock Text property bound to it. No other code present. If i set TxT in XAML on main window it wont work, binding works. If i add PropertyChangedCallback to that DependencyProperty it works also in XAML. So the question, is it mandatory to have PropertyChangedCallback for each property if i want to be able to set it directly in XAML? This is not clear to me, most don't mention about it, but it also forces me to adding internal control names to change their value in PropertyChangedCallback. The code is below. Can it be done some other way? MainWindow <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ...

WPF Combobox selectedindex binding

WPF Combobox selectedindex binding I have difficulties binding the selectedindex of a combobox to an object. This is my code: (Part of) CustomerClass public class Customer : INotifyPropertyChanged { public int CountryCode { get { return _CountryCode; } set { _CountryCode = value; NotifyPropertyChanged(); } } } 2a. (Part of) CustomListItem <ComboBox x:Name="cboCountryCode" Grid.Column="5" ItemsSource="{Binding}" DisplayMemberPath="LongName" SelectedIndex="{Binding CountryCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> 2b. (Part of) CustomListItem public partial class CustomerListItem : UserControl { public CustomerListItem() { InitializeComponent(); ObservableCollection<CountryCode> Liste = CountryCodes.Instance.List; cboCountryCode.DataContext = Liste; } (Part of) MainPage <ItemsControl Name="itcCustomers...

C# WPF Dispatcher in richtextbox.Document.Blocks

C# WPF Dispatcher in richtextbox.Document.Blocks all working ok when Im using in Thread: richtextbox1.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { this.richtextbox1.AppendText(text); })); but I get error "The calling thread cannot access this object because a different thread owns it. " when Im using in Thread: richtextbox1.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { this.richtextbox1.Document.Blocks.Add(paragraph); })); Im also get this error if I try with richtextbox1.Document = some_FlowDocument Can't find way how to resolve this in WPF Well what is paragraph ? If it's a UI element that you created in a different thread, that may well be the reason. As an aside, you may well find that using async/await is a simpler way of going about all of this. – Daisy Shipton Jun 23 at 20:07 ...