Override default styling in WPF TextBox, based on PresentationFramework.Aero

It seems to work if you put the Style as a lower-level resource, instead of in the same ResourceDictionary: <Grid xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”> <Grid.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source=”/PresentationFramework.Aero, Version=3.0.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml”/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Grid.Resources> <Border BorderBrush=”Blue” BorderThickness=”3″> <Border.Resources> <Style TargetType=”{x:Type TextBox}” BasedOn=”{StaticResource {x:Type TextBox}}”> <Setter Property=”Margin” Value=”2″ /> <Setter Property=”Padding” Value=”2″ /> </Style> </Border.Resources> <TextBox … Read more

How to trigger DataTemplateSelector when property changes?

As you requested an example with datatriggers in the comments, here you are: A FrameworkElement can only have EventTriggers, therefore you get the error Message Triggers collection members must be of type EventTrigger And also don’t use a ContentPresenter directly, it is meant to be used inside a ControlTemplate. Better use a ContentControl when you … Read more

Why doesn’t Visual Studio want me to add a new window to my WPF project?

Your project is probably configured as a WinForms project, or possibly as a class library. If it’s created as either of these, you are only able to add a WPF UserControl, unfortunately. Of course, there’s no technical reason for this limitation, so you can copy/paste one from another project or recreate/change your project to be … Read more

WPF Listbox auto scroll while dragging

Got it. Used the event DragOver of the ListBox, used the function found here to get the scrollviewer of the listbox and after that its just a bit of juggling with the Position. private void ItemsList_DragOver(object sender, System.Windows.DragEventArgs e) { ListBox li = sender as ListBox; ScrollViewer sv = FindVisualChild<ScrollViewer>(ItemsList); double tolerance = 10; double … Read more

Progressbar foreground color

just try with this <ProgressBar Height=”25″ IsIndeterminate=”True” Width=”150″ Foreground=”Red” ></ProgressBar> If it is not working as you required you have to modify the Style or ControlTemplate of Progressbar. To do that you can use Expression Blend from Microsoft or you can get a copy the existing template and modify it.

Using a StaticResource SolidColorBrush to define the Gradient Stop Colors

Ok, I found the problem: Using Color and not SolidColorBrush.. <Color x:Key=”colorbrushMedium”>#FF5A5A5A</Color> <Color x:Key=”colorbrushDark”>#FF222222</Color> <LinearGradientBrush> <GradientStop Color=”{StaticResource colorbrushMedium}”/> <GradientStop Color=”{StaticResource colorbrushDark}” Offset=”1″/> </LinearGradientBrush> This seems to solve my problem!

WPF Canvas, how to add children dynamically with MVVM code behind

ItemsControl is your friend: <Grid> <Image Source=”…”/> <ItemsControl ItemsSource=”{Binding Points}”> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemContainerStyle> <Style> <Setter Property=”Canvas.Left” Value=”{Binding X}”/> <Setter Property=”Canvas.Top” Value=”{Binding Y}”/> </Style> </ItemsControl.ItemContainerStyle> <ItemsControl.ItemTemplate> <DataTemplate> <Border BorderBrush=”Red” BorderThickness=”1″ Width=”{Binding Width}” Height=”{Binding Height}”/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Grid> The above assumes your VM exposes a collection of points via a Points property, and … Read more

Dynamically toggle visibility of WPF grid column from C# code

<ColumnDefinition> <ColumnDefinition.Style> <Style TargetType=”ColumnDefinition”> <Setter Property=”Width” Value=”*” /> <Style.Triggers> <DataTrigger Binding=”{Binding IsColumnVisible}” Value=”False”> <Setter Property=”Width” Value=”0″ /> </DataTrigger> </Style.Triggers> </Style> </ColumnDefinition.Style> </ColumnDefinition> Please do implement INotifyPropertyChanged in your ViewModel

ReSharper warnings with MVVM

You can use External Annotations to indicate to ReSharper the method is used and thus not to warn you. See the ReSharper docs on that here. You need to decorate any such methods with [UsedImplicitlyAttribute]. Before using the attribute, you see: and then, after applying the attribute: [UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] class NotUsed { public int Field1 { … Read more