Change theme at runtime

How you could do it: <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary x:Name=”ThemeDictionary”> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source=”/Themes/ShinyRed.xaml”/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> <!– … –> public partial class App : Application { public ResourceDictionary ThemeDictionary { // You could probably get it via its name with some query logic as well. get { return Resources.MergedDictionaries[0]; } } public void ChangeTheme(Uri uri) … Read more

Grouping items in a ComboBox

It is possible. Use a ListCollectionView with a GroupDescription as the ItemsSource and just provide a GroupStyle to your ComboBox. See sample below: XAML: <Window x:Class=”StackOverflow.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:local=”clr-namespace:StackOverflow” xmlns:uc=”clr-namespace:StackOverflow.UserControls” Title=”MainWindow” Height=”350″ Width=”525″> <StackPanel> <ComboBox x:Name=”comboBox”> <ComboBox.GroupStyle> <GroupStyle> <GroupStyle.HeaderTemplate> <DataTemplate> <TextBlock Text=”{Binding Name}”/> </DataTemplate> </GroupStyle.HeaderTemplate> </GroupStyle> </ComboBox.GroupStyle> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text=”{Binding Name}”/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> … Read more

Bubbling scroll events from a ListView to its parent

You need to capture the preview mouse wheel event in the inner listview MyListView.PreviewMouseWheel += HandlePreviewMouseWheel; Or in the XAML <ListView … PreviewMouseWheel=”HandlePreviewMouseWheel”> then stop the event from scrolling the listview and raise the event in the parent listview. private void HandlePreviewMouseWheel(object sender, MouseWheelEventArgs e) { if (!e.Handled) { e.Handled = true; var eventArg = … Read more

How do you determine if WPF is using Hardware or Software Rendering?

Check RenderCapability.Tier Graphics Rendering Tiers RenderCapability Class [UPDATE] RenderCapability.IsPixelShaderVersionSupported – Gets a value that indicates whether the specified pixel shader version is supported. RenderCapability.IsShaderEffectSoftwareRenderingSupported – Gets a value that indicates whether the system can render bitmap effects in software. RenderCapability.Tier – Gets a value that indicates the rendering tier for the current thread. RenderCapability.TierChanged – … Read more

Changing the string format of the WPF DatePicker

I have solved this problem with a help of this code. Hope it will help you all as well. <Style TargetType=”{x:Type DatePickerTextBox}”> <Setter Property=”Control.Template”> <Setter.Value> <ControlTemplate> <TextBox x:Name=”PART_TextBox” Text=”{Binding Path=SelectedDate, StringFormat=”dd MMM yyyy”, RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}” /> </ControlTemplate> </Setter.Value> </Setter> </Style>