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

Alternate background color in Listview XAML

I tried this and it works for me. <Window x:Class=”TryResponses.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:vm=”clr-namespace:TryResponses” xmlns:system=”clr-namespace:System;assembly=mscorlib” Title=”MainWindow” Height=”350″ Width=”525″> <Window.Resources> <vm:MainWindowViewModel x:Key=”MainWindowViewModel” /> </Window.Resources> <Grid Background=”LightGray” DataContext=”{StaticResource MainWindowViewModel}”> <Grid.Resources> <Style TargetType=”ListViewItem”> <Style.Triggers> <Trigger Property=”ItemsControl.AlternationIndex” Value=”0″> <Setter Property=”Background” Value=”LightBlue” /> </Trigger> <Trigger Property=”ItemsControl.AlternationIndex” Value=”1″> <Setter Property=”Background” Value=”LightGray” /> </Trigger> </Style.Triggers> </Style> <DataTemplate DataType=”system:String”> <!– put your data template … Read more

WPF binding not updating the view

You need to implement INotifyPropertyChanged in your ViewModel order to notify the View that the property has changed. Here’s a link to the MSDN page for it: System.ComponentModel.INotifyPropertyChanged The most important thing to note is that you should raise the PropertyChanged event in your property setter.

Why can’t I comment attributes in XAML?

Though you can’t comment out using the basic XAML markup, you can achieve the desired results by importing the Open XML markup namespace. xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″ xmlns:ignore=”http://www.galasoft.ch/ignore” mc:Ignorable=”ignore” <Label x:Name=”Gaga” FontSize=”20″ ignore:Content=”{Binding SomethingThatIsEmptyAtDesignTime}” Content=”LookAtMe!” /> This blog post describes how to do it.

WPF: How to style or disable the default ContextMenu of a TextBox

To style ContextMenu’s for all TextBoxes, I would do something like the following: First, in the resources section, add a ContextMenu which you plan to use as your standard ContextMenu in a textbox. e.g. <ContextMenu x:Key=”TextBoxContextMenu” Background=”White”> <MenuItem Command=”ApplicationCommands.Copy” /> <MenuItem Command=”ApplicationCommands.Cut” /> <MenuItem Command=”ApplicationCommands.Paste” /> </ContextMenu> Secondly, create a style for your TextBoxes, which … Read more

DataGrid column width doesn’t auto-update

The DataGrid will increase column sizes to fit as the data becomes longer, but it does not automatically decrease column sizes when the length of the data decreases. In your example, you’re right aligning the ‘Change’ column, and using the rest of the space for the ‘Name’ column. Now, when a ‘Change’ property grows large … Read more

How to see design-time data-binding in XAML editor (it works in runtime)?

Make sure that you have these definitions at the root tag of your xaml file (in your case the Window tag): xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″ xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″ mc:Ignorable=”d” Then, anywhere in the xaml (including the root tag) you can add this: d:DataContext=”{d:DesignInstance myNamespace:MyViewModel, IsDesignTimeCreatable=True}” Now you just need to make sure that you initialize the values in a constructor … Read more

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