why is this displaying date and time (rather than just date)?
<ListView Name="AttachmentsLB" Width="160" ItemsSource="{Binding Path=PicuAttachments}" >
<ListView.View>
<GridView>
<GridViewColumn Header="Start" DisplayMemberBinding="{Binding StartDate}" Width="80">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=., StringFormat=d}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Finish" DisplayMemberBinding="{Binding FinishDate}" Width="80">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=., StringFormat=d}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
I have also tried StringFormat = {}{0:d} and StringFormat = \{0:d\} with no success
problem of StringFormat on the wrong Binding
<GridViewColumn Header="Start" DisplayMemberBinding="{Binding StartDate, StringFormat=d}" Width="75">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
How about using this? Change the StringFormat in your binding :
DisplayMemberBinding="{Binding Path=startDate, StringFormat='yyyy-MM-dd'}"
Related
I have this GridViewColumn:
<GridViewColumn Width="180" Header="Status" DisplayMemberBinding="{Binding Status}"/>
Now i want to be able to change this Column text color also via code behind.
I try:
<GridViewColumn Width="180" Header="Status" DisplayMemberBinding="{Binding Status}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="Txt" Text="{Binding Status}" Foreground="Yellow" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
But it seems that the text color is not changing.
Since you already specifying the celltemplate for each item, you don't need to include the DisplayMemberBinding property, just remove it
<GridViewColumn Width="180" Header="Status">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="Txt" Text="{Binding Status}" Foreground="Yellow" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
I have this model:
Public Data
{
string name;
string age;
string id;
DateTime time;
}
Currently each ListView row contains all this 4 peoperties:
<ListView.View>
<GridViewColumn Width="20" DisplayMemberBinding="{Binding Index}" />
<GridViewColumn Width="320" DisplayMemberBinding="{Binding Description}" />
<GridViewColumn Width="150" DisplayMemberBinding="{Binding IPAddress}" />
<GridViewColumn Width="150" DisplayMemberBinding="{Binding time}" />
</GridView>
</ListView.View>
Now i want to make this ListView Width smaller so i want to each Row will contain 2 columns with 2 properties on each of them.
Is it possible ?
You need to override the default CellTemplate of GridViewColumn inorder to display your results inside a ListView.View
<GridViewColumn >
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Index}" />
<TextBlock Text="{Binding Description}"/>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn >
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding IPAddress}" />
<TextBlock Text="{Binding time}"/>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
Don't use a ListView
Use a ListBox DataTemplate with a Grid
I created list view with check box at column 1, but it's displaying only at header level and in rows i'm getting namespace name.
Here's the XAML code:
<ListView x:Name="ConfigurationFilesGrid" ItemsSource="{Binding ConfigurationFiles}"
SelectedItem="{Binding SelectedProgramFile}"
ScrollViewer.CanContentScroll="True"
PreviewMouseDoubleClick="ConfigurationFilesGrid_Reselect"
>
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.HeaderTemplate>
<DataTemplate>
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding ElementName=ConfigurationMainCtrl, Path=DataContext.IsAllConfigurationSelected}"/>
</DataTemplate>
</GridViewColumn.HeaderTemplate>
</GridViewColumn>
<GridViewColumn Header="{x:Static res:Resources.IDColNameTxt}" DisplayMemberBinding="{Binding ID}" />
<GridViewColumn Header="{x:Static res:Resources.TypeColHdr}" DisplayMemberBinding="{Binding DisplayType}" />
<GridViewColumn Header="{x:Static res:Resources.NameColNameTxt}" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Header="{x:Static res:Resources.MeterColNameTxt}" DisplayMemberBinding="{Binding MeterType}"/>
<GridViewColumn Header="{x:Static res:Resources.RateColNameTxt}" DisplayMemberBinding="{Binding RateDisplay}"/>
<GridViewColumn Header="{x:Static res:Resources.CommentColNameTxt}" DisplayMemberBinding="{Binding Comment}"/>
<GridViewColumn Header="{x:Static res:Resources.ModifiedDateColNameTxt}" DisplayMemberBinding="{Binding ModifiedDateTime}"/>
<GridViewColumn Header="{x:Static res:Resources.ProfileColNameTxt}" DisplayMemberBinding="{Binding Profile}"/>
</GridView>
</ListView.View>
</ListView>
And i'm getting list view like:
[](checkbox) ID Name Address
name 1 A X
name 2 B Y
But from above i'm getting checkbox only at header level not rows level so what change 'll reflect to checkbox from above xaml code.
Thanks for you help.
Nag
You've used the HeaderTemplate of the GridViewColumn, use the CellTemplate instead:
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding ElementName=ConfigurationMainCtrl, Path=DataContext.IsAllConfigurationSelected}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
I have a CheckedListBox control which is created by adding a DataTemplate with a CheckBox to a ListView. The problem is that I need columns too.
The following code doesn't display the check boxes:
<ListView x:Name="lbDatabases" Height="138" Width="498" Canvas.Left="44" Canvas.Top="146">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding DbName}" Header="Databases" Width="498"/>
</GridView>
</ListView.View>
<ListView.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsActive}" Checked="AnyChange" Unchecked="AnyChange" Style="{x:Null}" Content="{Binding DbName}"
Width="{Binding CheckWidth}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
However, if I comment out this code, everything works fine but no columns:
<ListView.View>
<GridView >
<GridViewColumn DisplayMemberBinding="{Binding DbName}" Header="Databases" Width="498"/>
</GridView>
</ListView.View>
Is there any way to have it all?
You need to define the data template as CellTemplate for your column:
<ListView x:Name="lbDatabases" Height="138" Width="498" Canvas.Left="44" Canvas.Top="146" >
<ListView.View >
<GridView >
<GridViewColumn Header="Databases" Width="498">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsActive}" Checked="AnyChange" Unchecked="AnyChange" Style="{x:Null}" Content="{Binding DbName}"
Width="{Binding CheckWidth}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
ok after struggling all morning I figured it out. They key here is to use a CellTemplate:
<ListView x:Name="lbDatabases" Height="138" Width="498" Canvas.Left="44" Canvas.Top="146" Style="{StaticResource ListViewStyle}">
<ListView.View >
<GridView>
<GridViewColumn Header="Databases" Width="498">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsActive}" Checked="AnyChange" Unchecked="AnyChange" Style="{x:Null}" Content="{Binding DbName}"
Width="{Binding CheckWidth}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Hi there im using C# 3.5, this could be possible ?
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("date", "{dd/MM/YYYY}") %>'></asp:TextBox></EditItemTemplate>
<ItemTemplate>
I was trying :
<ListView Margin="0,80,0,38" Name="dlstInformes" Grid.ColumnSpan="2" >
<ListView.View>
<GridView>
<GridViewColumn Header="Numero Informe" DisplayMemberBinding="{Binding Path= numeroinforme}" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock >
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Nombre" DisplayMemberBinding="{Binding Path= nombreinforme}" />
<GridViewColumn Header="Fecha Informe" DisplayMemberBinding="{Binding Path= fechainforme}" />
</GridView>
</ListView.View>
one solution here:
<ListView Margin="0,80,0,38" Name="dlstInformes" MouseDoubleClick="dlstInformes_MouseDoubleClick">
<ListView.View>
<GridView>
<GridViewColumn Header="Numero Informe" DisplayMemberBinding="{Binding Path= numeroinforme}" >
</GridViewColumn>
<GridViewColumn Header="Nombre" DisplayMemberBinding="{Binding Path= nombreinforme}" />
<GridViewColumn Header="Fecha Informe">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<Binding Path="fechainforme" StringFormat="{}{0:MM/dd/yyyy}"/>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
hopes helps...