In XAML: 1 2 3 4 5 6 7 8 9 <Button Name="myComboBox" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" /> <ComboBox Name="myButton" Style="{StaticResource {x:Static ToolBar.ComboBoxStyleKey}}" /> <Button Name=”myComboBox” Style=”{StaticResource {x:Static ToolBar.ButtonStyleKey}}” /> <ComboBox Name=”myButton” Style=”{StaticResource {x:Static ToolBar.ComboBoxStyleKey}}” /> In code (C#): 1 2 3 4 5 myButton.Style = (Style)FindResource(ToolBar.ButtonStyleKey); myComboBox.Style […]
Continue reading…
Posts tagged with 'WPF'
How to align text in DataGrid
The obvious solution is to set a HorizontalAlignment property of DataGridCell style: 1 2 3 4 5 6 7 <DataGridTextColumn Binding="{Binding Quantity, StringFormat=’#,0.0000′}" ClipboardContentBinding="{x:Null}" Header="Quantity"> <DataGridTextColumn.CellStyle> <Style TargetType="DataGridCell" > <Setter Property="HorizontalAlignment" Value="Right" /> </Style> </DataGridTextColumn.CellStyle> </DataGridTextColumn> <DataGridTextColumn […]
Continue reading…
How to create an object by class name using Reflection
1. When the class is defined in the same assembly, where your code is executed: 1 2 3 4 Dim _assemblyName As String = "MyAssembly" Dim _typeName As String = "MyNamespace.ExampleControl" Dim _type As Type = Assembly.Load(_assemblyName).GetType(_typeName, True) _control = Activator.CreateInstance(_type) Dim _assemblyName As String = “MyAssembly” Dim _typeName As String = “MyNamespace.ExampleControl” Dim _type […]
Continue reading…
How to handle Keyboard Focus Events globally in WPF
You will find quite a few cases when your application would need to handle the changing of keyboard focus globally at application level, not just on a single control element or even a form level. The simple adding listeners to all possible elements will not be an effective way and doesn’t guarantee you to have […]
Continue reading…