How to change MahApps.Metro dialog content template width?

Just create your own style that overrides the dialog Template (and add the DialogShownStoryboard too). <Style TargetType=”{x:Type Dialog:BaseMetroDialog}” x:Key=”NewCustomDialogStyle” BasedOn=”{StaticResource {x:Type Dialog:BaseMetroDialog}}”> <Setter Property=”Template”> <Setter.Value> <ControlTemplate TargetType=”{x:Type Dialog:BaseMetroDialog}”> <ControlTemplate.Resources> <Storyboard x:Key=”DialogShownStoryboard”> <DoubleAnimation AccelerationRatio=”.9″ BeginTime=”0:0:0″ Duration=”0:0:0.2″ Storyboard.TargetProperty=”Opacity” To=”1″ /> </Storyboard> </ControlTemplate.Resources> <Grid Background=”{TemplateBinding Background}”> <Border FocusVisualStyle=”{x:Null}” Focusable=”False”> <Grid> <Grid.RowDefinitions> <RowDefinition Height=”Auto” /> <RowDefinition Height=”*” /> <RowDefinition … Read more

Access ResourceDictionary items programmatically

Got it solved. I needed to: load my resource dictionary merge it with the application’s resources load my control template from the application resource As part of loading the resource dictionary, i also had to register the pack URI scheme. I then had to deal with some crazy COM based exceptions due to slight errors … Read more

Template Binding in Control template

I’d suggest using dynamic resources, e.g. define the template as follows: <ControlTemplate x:Key=”buttonTemplate” TargetType=”Button”> <Border CornerRadius=”5″ Margin=”15″ Cursor=”Hand”> <StackPanel Orientation=”Horizontal” Background=”Yellow”> <Image Source=”{DynamicResource ResourceKey=Img}” Height=”100″ Width=”100″ Margin=”5″></Image> <Label Content=”{TemplateBinding Content}” Background=”Transparent” Margin=”2″></Label> </StackPanel> </Border> </ControlTemplate> And use it like this: <Button Content=”Button” Template=”{StaticResource ResourceKey=buttonTemplate}”> <Button.Resources> <ImageSource x:Key=”Img”>SomeUri.png/</ImageSource> </Button.Resources> </Button>

How to create a WPF Window without a border that can be resized via a grip only?

If you set the AllowsTransparency property on the Window (even without setting any transparency values) the border disappears and you can only resize via the grip. <Window xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” Width=”640″ Height=”480″ WindowStyle=”None” AllowsTransparency=”True” ResizeMode=”CanResizeWithGrip”> <!– Content –> </Window> Result looks like:

Creating an image+text button with a control template?

Define a CustomControl like this in .cs public class MyButton : Button { static MyButton() { //set DefaultStyleKeyProperty } public ImageSource ImageSource { get { return (ImageSource)GetValue(ImageSourceProperty); } set { SetValue(ImageSourceProperty, value); } } // Using a DependencyProperty as the backing store for ImageSource. This enables animation, styling, binding, etc… public static readonly DependencyProperty ImageSourceProperty … Read more

How to fix this behavior in a WPF TabControl?

A simplified example. Collection item: using Simplified; namespace AddTabItem { public class TabVm : BaseInpc { string _header; bool _isPlaceholder; private string _text; public string Header { get => _header; set => Set(ref _header, value); } public bool IsPlaceholder { get => _isPlaceholder; set => Set(ref _isPlaceholder, value); } public string Text { get => … Read more

In WPF, why doesn’t TemplateBinding work where Binding does?

Found this forum post on MSDN: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0bb3858c-30d6-4c3d-93bd-35ad0bb36bb4/ It says this: A TemplateBinding is an optimized form of a Binding for template scenarios, analogous to a Binding constructed with {Binding RelativeSource={RelativeSource TemplatedParent}} Note from OP: Contrary to what it says in the documentation, in actuality, it should be this… {Binding RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay} I filed a … Read more