Make a XAML file internal in .NET

You need to add a x:ClassModifier=”internal” in the UserControl tag of the XAML file if you change the visibility of the class in the .cs file to internal. The file generated from the XAML file (e.g. MyControl.g.cs) needs to match the code-behind file (e.g. MyControl.cs). x:ClassModifier allows you to control the visibility of the part … Read more

Access codebehind variable in XAML

There are a few ways to do this. Add your variable as a resource from codebehind: myWindow.Resources.Add(“myResourceKey”, myVariable); Then you can access it from XAML: <TextBlock Text=”{StaticResource myResourceKey}”/> If you have to add it after the XAML gets parsed, you can use a DynamicResource above instead of StaticResource. Make the variable a property of something … Read more

How can I align a CheckBox with its content?

I know it’s too late, but here is a better solution, without setting margins. Margins should be set differently for different heights of TextBlock or Checkbox. <CheckBox VerticalAlignment=”Center” VerticalContentAlignment=”Center”> <TextBlock Text=”Well aligned Checkbox” VerticalAlignment=”Center” /> </CheckBox> Update: It’s worth checking out @nmarler’s comment below.

How to Avoid Firing ObservableCollection.CollectionChanged Multiple Times When Replacing All Elements Or Adding a Collection of Elements

ColinE is right with all his informations. I only want to add my subclass of ObservableCollection that I use for this specific case. public class SmartCollection<T> : ObservableCollection<T> { public SmartCollection() : base() { } public SmartCollection(IEnumerable<T> collection) : base(collection) { } public SmartCollection(List<T> list) : base(list) { } public void AddRange(IEnumerable<T> range) { foreach … Read more

Set CornerRadius on button template

You’re not limited to the dependency properties of the control you’re templating. In this case, while Button does not have a CornerRadius property, Border does, so you can use Border.CornerRadius instead: <Style TargetType=”Button” x:Key=”TabButton”> <Setter Property=”Background” Value=”White” /> <Setter Property=”TextBlock.TextAlignment” Value=”Center” /> <Setter Property=”Template”> <Setter.Value> <ControlTemplate TargetType=”Button”> <Border CornerRadius=”{TemplateBinding Border.CornerRadius}” Background=”White” BorderBrush=”#ccc” BorderThickness=”0,1,1,0″ > <ContentPresenter … Read more