Hiding a button in WPF

Try one of these: button.Visibility = Visibility.Hidden; button.Visibility = Visibility.Collapsed; Hidden hides the button but the button will still take up space in the UI. Collapsed will collapse the button such that it has zero width and height.

How to center an element in wpf canvas

I came across this post, because I was searching for a way to center an element within a Canvas in XAML only, instead of using Attached Properties. Just in case, you came for the same reason: <Canvas x:Name=”myCanvas”> <Grid Width=”{Binding ActualWidth, ElementName=myCanvas}” Height=”{Binding ActualHeight, ElementName=myCanvas}”> <Label Content=”Hello World!” HorizontalAlignment=”Center” VerticalAlignment=”Center” /> </Grid> </Canvas> One more … Read more

Difference between {Binding PropertyName} and {Binding Path=PropertyName}

There is a significant difference here which you will run into as soon as you have a complex property path with typed parameters. Conceptually they are equivalent as they both end up setting the Binding.Path, one via the parameterized Binding constructor, the other directly via the property. What happens internally is very different though as … Read more

How to center the content of cells in a data grid?

Final solution: <Style x:Key=”DataGridContentCellCentering” TargetType=”{x:Type DataGridCell}”> <Setter Property=”Template”> <Setter.Value> <ControlTemplate TargetType=”{x:Type DataGridCell}”> <Grid Background=”{TemplateBinding Background}”> <ContentPresenter VerticalAlignment=”Center” /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>