How to bind Close command to a button

All it takes is a bit of XAML… <Window x:Class=”WCSamples.Window1″ xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”> <Window.CommandBindings> <CommandBinding Command=”ApplicationCommands.Close” Executed=”CloseCommandHandler”/> </Window.CommandBindings> <StackPanel Name=”MainStackPanel”> <Button Command=”ApplicationCommands.Close” Content=”Close Window” /> </StackPanel> </Window> And a bit of C#… private void CloseCommandHandler(object sender, ExecutedRoutedEventArgs e) { this.Close(); } (adapted from this MSDN article)

‘Graying Out’ a WPF button image?

Use a trigger in the Image style. (It would be more natural to put it in the Button style, but the Button style can’t easily affect the Image for annoying technical reasons. It could be done in the Button’s ControlTemplate but that’s overkill for what you want here.) <Button> <Image Source=”something.png”> <Image.Style> <Style TargetType=”Image”> <Style.Triggers> … Read more

Custom vs User control

Choice is not only between user control and custom control, but among user control, custom control, customizing control template, customizing data template, header template (for collection based controls), attached properties. Refer to Control Authoring overview I go by following order of consideration Attached Properties : If functionality can be achieved, I use attached properties. Example, … Read more

How to create/make rounded corner buttons in WPF?

I know this post is super old, but I have an answer that’s surprisingly missing from the above and is also much simpler than most. <Button> <Button.Resources> <Style TargetType=”Border”> <Setter Property=”CornerRadius” Value=”5″/> </Style> </Button.Resources> </Button> Since the default ControlTemplate for the Button control uses a Border element, adding a style for Border to the Button’s … Read more

WPF StringFormat on Label Content

The reason this doesn’t work is that the Label.Content property is of type Object, and Binding.StringFormat is only used when binding to a property of type String. What is happening is: The Binding is boxing your MaxLevelOfInvestment value and storing it the Label.Content property as a boxed decimal value. The Label control has a template … Read more

The default value type does not match the type of the property

Default value for DP does not match your type. Change public static readonly DependencyProperty ToothProperty = DependencyProperty.Register(“Tooth”, typeof(Tooth), typeof(ToothUI), new PropertyMetadata(0)); to public static readonly DependencyProperty ToothProperty = DependencyProperty.Register(“Tooth”, typeof(Tooth), typeof(ToothUI), new PropertyMetadata(default(Tooth))); Or simply omit setting default value for your DP: public static readonly DependencyProperty ToothProperty = DependencyProperty.Register(“Tooth”, typeof(Tooth), typeof(ToothUI));

Link button in wpf

If you don’t want any of the normal Button style and just want something that looks like a hyperlink you could start with this <Button Margin=”5″ Content=”Test” Cursor=”Hand”> <Button.Template> <ControlTemplate TargetType=”Button”> <TextBlock TextDecorations=”Underline”> <ContentPresenter /> </TextBlock> </ControlTemplate> </Button.Template> <Button.Style> <Style TargetType=”Button”> <Setter Property=”Foreground” Value=”Blue” /> <Style.Triggers> <Trigger Property=”IsMouseOver” Value=”true”> <Setter Property=”Foreground” Value=”Red” /> </Trigger> </Style.Triggers> … Read more

Formatting text in a TextBlock

You need to use Inlines: <TextBlock.Inlines> <Run FontWeight=”Bold” FontSize=”14″ Text=”This is WPF TextBlock Example. ” /> <Run FontStyle=”Italic” Foreground=”Red” Text=”This is red text. ” /> </TextBlock.Inlines> With binding: <TextBlock.Inlines> <Run FontWeight=”Bold” FontSize=”14″ Text=”{Binding BoldText}” /> <Run FontStyle=”Italic” Foreground=”Red” Text=”{Binding ItalicText}” /> </TextBlock.Inlines> You can also bind the other properties: <TextBlock.Inlines> <Run FontWeight=”{Binding Weight}” FontSize=”{Binding Size}” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)