WPF: Changing Resources (colors) from the App.xaml during runtime

It looks like you’re trying to do some sort of skinning? I’d recommend defining the resources in a Resource Dictionary contained in a separate file. Then in code (App.cs to load a default, then elsewhere to change) you can load the resources as so: //using System.Windows ResourceDictionary dict = new ResourceDictionary(); dict.Source = new Uri(“MyResourceDictionary.xaml”, … Read more

System.Windows.Controls.MenuItem without icon area

You can achieve it by defining ItemsPanel property of MenuItem. Create an ItemsPanelTemplate resource <ItemsPanelTemplate x:Key=”MenuItemPanelTemplate”> <StackPanel Margin=”-20,0,0,0″ Background=”White”/> </ItemsPanelTemplate> Add below MenuItem style to resources and you are done. <Style TargetType=”{x:Type MenuItem}”> <Setter Property=”ItemsPanel” Value=”{StaticResource MenuItemPanelTemplate}”/> </Style> To apply same Style to a ContextMenu, you need to create one more Style as following- <Style … Read more

WPF: How to customize SelectionBoxItem in ComboBox

I would do it like this: <Window.Resources> <DataTemplate x:Key=”NormalItemTemplate” …> … </DataTemplate> <DataTemplate x:Key=”SelectionBoxTemplate” …> … </DataTemplate> <DataTemplate x:Key=”CombinedTemplate”> <ContentPresenter x:Name=”Presenter” Content=”{Binding}” ContentTemplate=”{StaticResource NormalItemTemplate}” /> <DataTemplate.Triggers> <DataTrigger Binding=”{Binding RelativeSource={RelativeSource FindAncestor,ComboBoxItem,1}}” Value=”{x:Null}”> <Setter TargetName=”Presenter” Property=”ContentTemplate” Value=”{StaticResource SelectionBoxTemplate}” /> </DataTrigger> </DataTemplate.Triggers> </DataTemplate> </Window.Resources> … <ComboBox ItemTemplate=”{StaticResource CombinedTemplate}” ItemsSource=”…” … /> The reason this works is that CombinedTemplate … Read more

Is this possible to customize printf?

Sorry, but some answers are incorrect on Linux with Glibc On Linux with a GNU Glibc, you can customize printf: you would call register_printf_function to e.g. define the meaning of %Y in your printf format strings. However, this behavior is Glibc specific, and might even become obsolete… I’m not sure I would recommend this approach! … Read more

How to customize list preference radio button

Styling the ListPreference from XML is not directly possible. The problem is that ListPreference (through DialogPreference) calls AlertDialog.Builder(Context) to build its Dialog, rather than AlertDialog.Builder(Context context, int themeResourceId). While the latter allows for providing a theme, the former does not, causing it to fall back to a default Android theme. For a project, I needed … Read more

Is there a “right” way to have NSTextFieldCell draw vertically centered text?

The other answers didn’t work for multiple lines. Therefore I initially continued using the undocumented cFlags.vCentered property, but that caused my app to be rejected from the app store. I ended up using a modified version of Matt Bell’s solution that works for multiple lines, word wrapping, and a truncated last line: -(void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView … Read more