How to set the style programmatically
In the code-behind file of the control, try: this.Style = Resources[“ResourceName”] as Style;
In the code-behind file of the control, try: this.Style = Resources[“ResourceName”] as Style;
Here’s a basic MVVM compliant way of getting the behaviour you want: MainWindow.xaml <Window x:Class=”WpfApplication1.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” Title=”MainWindow” Height=”350″ Width=”525″> <StackPanel> <ComboBox Margin=”30,5,30,5″ IsEditable=”True” ItemsSource=”{Binding Items}” SelectedItem=”{Binding SelectedItem}” Text=”{Binding NewItem, UpdateSourceTrigger=LostFocus}”/> <TextBox Margin=”30,5,30,5″ /> </StackPanel> </Window> MainWindow.cs public partial class MainWindow : Window, INotifyPropertyChanged { private string _selectedItem; private ObservableCollection<string> _items = new ObservableCollection<string>() { … Read more
You can grab the UI Dispatcher from the static application instance: Application.Current.Dispatcher You may want to check Application.Current for null first, as it can be cleared during a shutdown sequence.
In 3.5SP1 / 3.0SP2, they also added a new property to the ValidationRule base, namely, ValidatesOnTargetUpdated=”True”. This will call the validation as soon as the source object is bound, rather than only when the target control is updated. That may not be exactly what you want, but it’s not bad to see initially all the … Read more
The setters in WPF styles are checked during compile time; CSS styles are applied dynamically. You have to specify a type so that WPF can resolve the properties in the setters to the dependency properties of that type. You can set the target type to base classes that contain the properties you want and then … Read more
Write your code in window1. private void Button_Click(object sender, RoutedEventArgs e) { window2 win2 = new window2(); win2.Show(); }
Like you, when I was getting started and wanted to understand how / what was going on and working with templates, it took a lot of trial and error. Hopefully my research and some step-by-step components can help you customize to your liking and KNOWING where things are coming from. First, when trying to understand … Read more
There might be an easier way to do this but I got it to work by using the GetIndex() method on the DataGridRow class. This returns the index in to the data source so might not be exactly what you’re after. the xaml <Window x:Class=”WpfApplication1.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:sys=”clr-namespace:System;assembly=mscorlib” xmlns:local=”clr-namespace:WpfApplication1″ Title=”MainWindow” Height=”350″ Width=”525″> <DataGrid> <DataGrid.Columns> <DataGridTextColumn … Read more
This brief article explains how you can achieve this. If you find yourself in need to open a WPF Window from a WinForms program, this is one way to do it (works for me): Create/Add a new project of type WPF Custom Control Library Add a new Item of type Window (WPF) Do your thing … Read more
Providing a custom component turned out to be the best solution. I use it like this in my code <Controls:Arc Center=”{Binding Path=PreviousMousePositionPixels}” Stroke=”White” StrokeDashArray=”4 4″ SnapsToDevicePixels=”True” StartAngle=”0″ EndAngle=”{Binding Path=DeltaAngle}” SmallAngle=”True” Radius=”40″ /> SmallAngle when true will render the small angle between the points irrespective of order of StartAngle and EndAngle. When SmallAngle is false the … Read more