style that I have to create in code-behind. It has a checkbox that looks like this..
<GridView>
<GridViewColumn Width="30">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<CheckBox/>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>-->
<GridViewColumn Header="Groups" DisplayMemberBinding="{Binding Groups}"/>
<GridViewColumn Header="SiteTitle" DisplayMemberBinding="{Binding SiteTitle}"/>
<GridViewColumn Header="SiteUrl" DisplayMemberBinding="{Binding SiteUrl}"/>
</GridView>
How I do in code-behind?
Just add this style in Resources and give it a x:Name.Let's assume the given name is CustomCheckboxTemplate , then a sample code will look like :
DynamicallyCreatedCheckbox.Style = (Style)FindResource("CustomCheckboxTemplate");
Hope this helps :)
Related
I have a ListView that is going to show some values of a Google calendar event, the application let you see what events do you have for one specific date, and you can add more, edit, or delete the events.
By the moment, i am showing all the events just for testing, and i am using a gridview for the properties to reorder and the headers, but the event have too much values and is too wide, what i want is split this columns in two rows
Column A, Column B, Column C
info info info
Column D, Column E...
info info
for each element.
Instead of
Column A, B, C...
info info info info
in one row.
is there any way to do this with gridview? or i have to resign myself and do something similar with custom controls or Grids.
My listview
<ListView Background="Transparent"
x:Name="DatosEvento"
Margin="5"
MinWidth="{Binding ActualWidth, ElementName=Calendar}"
Width="Auto"
ItemsSource="{Binding Path=Eventos}"
Grid.Row="1"
Grid.Column="1">
<ListView.View>
<GridView>
<GridViewColumn Header="Organizador" DisplayMemberBinding="{Binding Path=Organizer.DisplayName}" />
<GridViewColumn Header="Correo Organizador">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Organizer.Email}" TextDecorations="Underline" Foreground="Blue" Cursor="Hand" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Nombre Evento" DisplayMemberBinding="{Binding Path=Summary}"/>
<GridViewColumn Header="Estado" DisplayMemberBinding="{Binding Path=Status}"/>
<GridViewColumn Header="Fecha Fin" DisplayMemberBinding="{Binding Path=End.Date}"/>
<GridViewColumn Header="Actualizado el" DisplayMemberBinding="{Binding Path=Updated.Date}"/>
<GridViewColumn Header="Enlace">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=HtmlLink}" TextDecorations="Underline" Foreground="Blue" Cursor="Hand" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
as i cant mark a comment as the solution, i have change the gridview for a mix of wrap and stackpanels, as #BionicCode suggested (he suggested the wrappanel i just added some stackpanels to do something similar to the gridview)
Something like this:
public class EffectViewModel
{
public string Name ...
ObservableCollection<KeyValuePair<int,object>> settings
public ObservableCollection<KeyValuePair<int,object>> Settings
{
get {return this.settings;}
set
{
this.settings = value;
this.RaisePropertyChanged ( "Settings" );
}
}
}
Right now I am trying to bind it like this:
EffectWindowViewModel.Effects is of type ObservableCollection<EffectViewModel>.
<ListView Width="1000"
Height="600"
ItemsSource="{Binding EffectWindowViewModel.Effects}">
<ListView.View>
<GridView>
<GridViewColumn Width="Auto"
DisplayMemberBinding="{Binding Key}"
Header="Name" />
<GridViewColumn Width="Auto"
DisplayMemberBinding="{Binding Value}"
Header="Value" />
</GridView>
</ListView.View>
</ListView>
But I don't know how to specify .Settings property.
Any ideas?
your actual binding will not work cause EffectViewModel has no key and Value Property. i really dont know what your listview should display. if you want a list of EffectViewModels then the Itemssource is right. if you want further for each EffectViewModel to display the settings. then you need somekind of itemsscontrol with Itemssource={Binding Settings}. this itemsscontrol of course will need a itemsstemplate with your Key and Value.
i have no VS here atm, but your GridViewColumn needs a kind of CellTemplate. and this template should consist of a itemscontrol. because you have 2collections!
this code is probably not right but should take you in the right direction
<ListView Width="1000"
Height="600"
ItemsSource="{Binding EffectWindowViewModel.Effects}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Settings}">
<GridViewColumn.CellTemplate>
<DataTemplatex:Key="myCell4Settings">
<ListView ItemsSource="{Binding.}">
<ListView.View>
<GridView>
<GridViewColumn Width="Auto"
DisplayMemberBinding="{Binding Key}"
Header="Name" />
<GridViewColumn Width="Auto"
DisplayMemberBinding="{Binding Value}"
Header="Value" />
</GridView>
</ListView.View>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</ListView>
</DataTemplate>
</GridView>
</ListView.View>
btw you could also use 2 lists independent. one parent Combobox or listbox (x:Name=parent) with itemssource=EffectWindowViewModel.Effects and a second ListView like you have, with the itemssource binding:
ItemsSource="{Binding ElementName=parent, Path=SelectedItem.Settings}"
You could try:
ItemsSource="{Binding ElementName=Settings, Path=EffectWindowViewModel.Effects}"
I have a user control that contains a listview. In the windows where I use this usercontrol, I want to be able to do something like what is shown below where I set the template for a control within the user control.
<ct:AutoCompleteComboBox
SelectedValue="{Binding Path=SelectedCountry}"
ItemsSource="{Binding Path=CountryList}" >
<ct:AutoCompleteComboBox.DropDownList >
<ListView
Background="Blue"
MinWidth="150"
MaxHeight="200">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header=" Name" DisplayMemberBinding="{Binding Name}" >
</GridViewColumn>
<GridViewColumn Header="Desc" DisplayMemberBinding="{Binding Description}" >
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</ct:AutoCompleteComboBox.DropDownList>
</ct:AutoCompleteComboBox>
How do I go about doing this? I found that if I made AutoCompleteComboBox.DropDownList a dependency property, then the code would compile. However, this DropDownList property is not actually added to my control (it is added to the parent container of ct:AutoCompleteComboBox).
Any idea of the proper way to do this?
Thanks in advance
Bind subcontrol's property you want to be available outside to the property you created in the container control.
I've created a ListView with a GridView component in it. Now trying to fill one of the cells with an icon (PNG) like in the code sample below (save_icon.png):
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="Auto" DisplayMemberBinding="{Binding Date}" />
<GridViewColumn Header="Time" Width="Auto" DisplayMemberBinding="{Binding Time}" />
<GridViewColumn Header="FriendlyName" Width="Auto" DisplayMemberBinding="{Binding FriendlyName}" />
<GridViewColumn Width="Auto">
<Image Source="save_icon.png" />
</GridViewColumn>
</GridView>
</ListView.View>
Visual Studio gives me an error on the line, where i put the icon into the column (ERROR: "Error 35: The file save_icon.png is not part of the project or its 'Build Action' property is not set to 'Resource'.") I added the icon to the project as a resource and when i start the app, everything works (the icon appears at the right place). But the WPF designer window can't be reloaded and i'm not able to see changes in the designer, when i change the XAML code.
Can somebody explain this error or am i doing something wrong?
Thanks for every hint in advance!
I found a solution for my problem. Just use a Cell- and DataTemplate inside of a GridViewColumn. The follwoing XAML-Code-Snippet does exactly what i need and the wpf designer reloads without any problems:
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="Auto" DisplayMemberBinding="{Binding Date}" />
<GridViewColumn Header="Time" Width="Auto" DisplayMemberBinding="{Binding Time}" />
<GridViewColumn Header="FriendlyName" Width="Auto" DisplayMemberBinding="{Binding FriendlyName}" />
<GridViewColumn Width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Source="Resources\saveicon.png"></Image>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
I believe it is because you have an underscore in your image filename. Try removing the underscore and rebuilding.
How to display treeview inside a list view, actually this listview has headers namely workbook, description,date, so when I display the tree view inside the listview, the treeview should open as per the listview headers.
My question is :
1. How to insert treeview inside Listview and my xaml code is
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ListView Name="lstViewWorkbooks" HorizontalAlignment="Left" >
<ListView.View >
<GridView >
<GridViewColumn Header="WorkBook" Width="200" DisplayMemberBinding="{Binding AnyWorkbook}" />
<GridViewColumn Header="Description" Width="660" DisplayMemberBinding="{Binding DescName}" />
<GridViewColumn Header="Date" Width="183" DisplayMemberBinding="{Binding WorkbookDate}" />
</GridView>
</ListView.View>
<TreeView HorizontalAlignment="Left" Margin="195,76,0,-76" Name="tviewPojectView" Width="120" />
</ListView>
</ScrollViewer>
I am using MVP architecture, with C# and wpf.
The treeview in the above xaml code is enough to display the data?
Please help me
Thanks
Ramm
If you want the tree view inside a cell in your grid, you need to place it inside the cell template for the correct column like this:
<GridViewColumn Header="WorkBook" Width="200" DisplayMemberBinding="{Binding AnyWorkbook}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TreeView HorizontalAlignment="Left" Margin="195,76,0,-76" Name="tviewPojectView" Width="120" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>