For the life of me I can't get the gridsplitter control to behave in the way I want.
In the below layout, I need a gridspliter to the right of each listview, that will expand or contract that listview and resize the other listviews appropriately.
The expanders and their (green) panels should not resize.
Please help! This control is driving me nuts.
MainWindow.xaml:
<Window x:Class="LayoutTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="400" MinWidth="1000">
<Grid Name="root" SizeChanged="root_SizeChanged">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="200" Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition MinWidth="200" Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition MinWidth="200" Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ListView Grid.Column="0" MinWidth="100">
<ListViewItem>a</ListViewItem>
<ListViewItem>b</ListViewItem>
<ListViewItem>c</ListViewItem>
<ListViewItem>d</ListViewItem>
<ListView.View>
<GridView>
<GridViewColumn Header="a" Width="100" />
<GridViewColumn Header="b" Width="100" />
<GridViewColumn Header="c" Width="100" />
<GridViewColumn Header="d" Width="100" />
</GridView>
</ListView.View>
</ListView>
<Expander Name="xleft" Grid.Column="1" ExpandDirection="Left" Expanded="Expanded">
<Border MinWidth="300" Width="300" Background="Green" >
<TextBlock Text="{Binding ElementName=root,Path=ActualWidth}" />
</Border>
</Expander>
<ListView Grid.Column="2" MinWidth="100">
<ListViewItem>a</ListViewItem>
<ListViewItem>b</ListViewItem>
<ListViewItem>c</ListViewItem>
<ListViewItem>d</ListViewItem>
<ListView.View>
<GridView>
<GridViewColumn Header="a" Width="100" />
<GridViewColumn Header="b" Width="100" />
<GridViewColumn Header="c" Width="100" />
<GridViewColumn Header="d" Width="100" />
</GridView>
</ListView.View>
</ListView>
<Expander Name="xmiddle" Grid.Column="3" ExpandDirection="Left" Expanded="Expanded">
<Border MinWidth="300" Width="300" Background="Green" >
<TextBlock Text="{Binding ElementName=root,Path=ActualWidth}" />
</Border>
</Expander>
<ListView Grid.Column="4" MinWidth="100">
<ListViewItem>a</ListViewItem>
<ListViewItem>b</ListViewItem>
<ListViewItem>c</ListViewItem>
<ListViewItem>d</ListViewItem>
<ListView.View>
<GridView>
<GridViewColumn Header="a" Width="100" />
<GridViewColumn Header="b" Width="100" />
<GridViewColumn Header="c" Width="100" />
<GridViewColumn Header="d" Width="100" />
</GridView>
</ListView.View>
</ListView>
<Expander Name="xright" Grid.Column="5" ExpandDirection="Left" Expanded="Expanded">
<Border MinWidth="300" Width="300" Background="Green" >
<TextBlock Text="{Binding ElementName=root,Path=ActualWidth}" />
</Border>
</Expander>
</Grid>
</Window>
MainWindow.xaml.cs:
using System.Windows;
using System.Windows.Controls;
namespace LayoutTest
{
/// <summary>
/// Interaction logic for Window2.xaml
/// </summary>
public partial class MainWindow : Window
{
Expander[] expanders;
Expander priority;
public MainWindow()
{
InitializeComponent();
expanders = new Expander[] {xleft,xmiddle,xright};
}
private void Expanded(object sender, RoutedEventArgs e)
{
if (sender is Expander) priority = sender as Expander;
if (root.ActualWidth > this.ActualWidth)
{
foreach (Expander ep in expanders)
{
if (ep.IsExpanded && priority != null && !ep.Name.Equals(priority.Name) )
{
ep.IsExpanded = false;
break;
}
}
}
}
private void root_SizeChanged(object sender, SizeChangedEventArgs e)
{
Expanded(null,new RoutedEventArgs());
}
}
}
It's not ideal, but this is the solution I'm going with:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="100" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="100" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="100" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="Green">
</Border>
<Expander Name="ex1" Grid.Column="1" ExpandDirection="Left" Expanded="ex_Expanded">
<Border Background="Blue" MinWidth="200" MaxWidth="200">
</Border>
</Expander>
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Left" ResizeBehavior="PreviousAndNext" VerticalAlignment="Stretch" Background="Red" />
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Right" ResizeBehavior="PreviousAndNext" VerticalAlignment="Stretch" Background="Red" />
<Border Grid.Column="2" Background="Green">
</Border>
<Expander Name="ex2" Grid.Column="3" ExpandDirection="Left" Expanded="ex_Expanded">
<Border Background="Blue" MinWidth="200" MaxWidth="200">
</Border>
</Expander>
<GridSplitter Grid.Column="3" Width="5" HorizontalAlignment="Left" ResizeBehavior="PreviousAndNext" VerticalAlignment="Stretch" Background="Red" />
<GridSplitter Grid.Column="3" Width="5" HorizontalAlignment="Right" ResizeBehavior="PreviousAndNext" VerticalAlignment="Stretch" Background="Red" />
<Border Grid.Column="4" Background="Green">
</Border>
<Expander Name="ex3" Grid.Column="5" ExpandDirection="Left" Expanded="ex_Expanded">
<Border Background="Blue" MinWidth="200" MaxWidth="200">
</Border>
</Expander>
</Grid>
Related
i have working state.
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn
Width="120"
DisplayMemberBinding="{Binding Status}"
Header="Durumu" />
<GridViewColumn
Width="180"
DisplayMemberBinding="{Binding FromWho}"
Header="Kimden" />
<GridViewColumn
Width="200"
DisplayMemberBinding="{Binding Address}"
Header="Adres" />
<GridViewColumn
Width="50"
DisplayMemberBinding="{Binding Code}"
Header="Kodu" />
<GridViewColumn
Width="0"
DisplayMemberBinding="{Binding Order}"
Header="Sipariş" />
</GridView.Columns>
</GridView>
</ListView.View>
but this not enough for me.
I have wpf application. and I'm learning Binding
i can use with Default listview binding like above code (listview). but i making editing customize listview. and bind data
however, while i try display data just appear myList's System name.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="3*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<DockPanel Grid.Row="1" VerticalAlignment="Center">
<ListView
x:Name="listVActiveOrder"
Width="560"
Height="222"
Margin="10,10,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
SelectionChanged="ListVActiveOrder_SelectionChanged"
ItemsSource="{Binding TakingOrderList}">
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="GroupItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Address}" />
<TextBlock Grid.Column="1" Text="{Binding FromWho}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
</DockPanel>
<ListBox
x:Name="listProcessed"
Grid.Row="2"
Width="79"
Height="29"
Margin="721,16,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Visibility="Hidden" />
</Grid>
public LoginResponse loginResponse;
public RestClient client;
public listviewDeneme()
{
client = new RestClient(Constants.APIURL);
InitializeComponent();
}
private void ListVActiveOrder_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
listVActiveOrder.DataContext = new TakingOrderVM();
}
Where is my fault?
You can either set the DisplayMemberPath property of the ListView or ListBox to a name of the property of the TakingOrder class that you want to display:
<ListBox
x:Name="listProcessed"
DisplayMemberPath="FromWho"
...
Or you could define an ItemTemplate:
<ListView
x:Name="listVActiveOrder"
Width="560"
Height="222"
Margin="10,10,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
SelectionChanged="ListVActiveOrder_SelectionChanged"
ItemsSource="{Binding TakingOrderList}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Address}" />
<TextBlock Grid.Column="1" Text="{Binding FromWho}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
There is no reason to use a ListView over a ListBox if you don't intend to use a GridView though.
Hey Everyone I am trying to figure out why my content will not stretch horizontally to fit my ListView items. I have HorizontalContentAlignment set to stretch, I used almost this exact layout on a second page and the content stretches on the second page. So not exactly sure what is going on and why the content won't stretch.
Here is a picture of what I am talking about
here is the code
<Border>
<Border.Background>
<ImageBrush ImageSource="/Backgrounds/BlueWaveBackground.jpg"/>
</Border.Background>
<Grid>
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" HorizontalAlignment="Center" >
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" TextBlock.TextAlignment="Center">
<Border CornerRadius="10"
Background="{StaticResource ForegroundLightBrush}"
Padding="15 10 15 15"
Width="700"
Margin="50 50 50 0">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!--First Last Username-->
<StackPanel Grid.Column="0" HorizontalAlignment="Center">
<TextBlock Text="First Name:" Margin="0 10 10 0" />
<TextBlock Text="Last Name:" Margin="0 14 10 0" />
<TextBlock Text="Username:" Margin="0 16 10 0"/>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical" >
<TextBox Grid.Row="0" Text="{Binding SelectedUser.FirstName}"/>
<TextBox Text="{Binding SelectedUser.LastName}"/>
<TextBox Text="{Binding SelectedUser.UserName}"/>
</StackPanel>
<!--Email and EmployeeType-->
<StackPanel Grid.Column="2" HorizontalAlignment="Center">
<TextBlock Text="Email:" Margin="95 10 10 0" />
<TextBlock Text="Employee Type:" Margin="10 14 10 0" />
</StackPanel>
<StackPanel Grid.Column="3" Orientation="Vertical" >
<TextBox Grid.Row="0" Text="{Binding SelectedUser.Email}"/>
<TextBox Text="{Binding SelectedUser.EmployeeType}"/>
</StackPanel>
</Grid>
<StackPanel Orientation="Horizontal">
<Button Content="Add New User" Margin="15"/>
<Button Content="Update User" Margin="15"/>
<Button Content="Delete User" Margin="15"/>
<Button Content="Clear User Info" Margin="15"/>
</StackPanel>
<!--Data grid-->
<ListView ItemsSource="{Binding Users}"
SelectedItem="{Binding SelectedUser}"
Margin="0,20,0,0"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
MaxHeight="150"
x:Name="List">
<ListView.View>
<GridView AllowsColumnReorder="True" ColumnHeaderToolTip="Users">
<GridViewColumn Header="First Name" Width="Auto" DisplayMemberBinding="{Binding FirstName}"/>
<GridViewColumn Header="Last Name" Width="Auto" DisplayMemberBinding="{Binding LastName}"/>
<GridViewColumn Header="Email" Width="Auto" DisplayMemberBinding="{Binding Email}"/>
<GridViewColumn Header="UserName" Width="Auto" DisplayMemberBinding="{Binding UserName}"/>
<GridViewColumn Header="Employee Type" Width="Auto" DisplayMemberBinding="{Binding EmployeeType}"/>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
</Border>
</StackPanel>
</ScrollViewer>
</Grid>
</Border>
Thanks for any suggestions!
I found the solution. I had to set my border width to auto.
<Border CornerRadius="10"
Background="{StaticResource ForegroundLightBrush}"
Padding="15 10 15 15"
Width="auto"
Margin="50 50 50 0">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
I have done some googling and searches and find many questions on StackOverFlow that come close to helping me but all the ideas from them still give me binding expression errors in one form or another with most always mentioning it cannot find the source.
Cannot find source for binding with reference 'ElementName=filesList'.
View that calls control template:
<Expander
DockPanel.Dock="Top"
SnapsToDevicePixels="True"
Grid.Column="1" Grid.ColumnSpan="1" Grid.Row="3" Grid.RowSpan="1"
Header="Files"
IsExpanded="True"
ExpandDirection="Down"
Background="{DynamicResource DynamicFrmBG}" Foreground="{DynamicResource DynamicFrmFG}"
>
<ContentControl
SnapsToDevicePixels="True"
Template="{StaticResource filesTemplate}"
/>
</Expander>
Control Template Code Snippet (Comment in this code is another example of different things I have tried):
<ControlTemplate x:Key="filesTemplate">
<Grid
SnapsToDevicePixels="True"
>
<Grid.RowDefinitions>
<RowDefinition Height="5" />
<RowDefinition Height="Auto" />
<RowDefinition Height="1*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="5" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="5" />
</Grid.ColumnDefinitions>
<ContentControl
SnapsToDevicePixels="True"
Grid.Column="1" Grid.ColumnSpan="1" Grid.Row="2" Grid.RowSpan="1"
Margin="0,0,0,0"
Content="{Binding Files}"
ContentTemplate="{StaticResource filesListTemplate}"
/>
<StackPanel
SnapsToDevicePixels="True"
Grid.Column="1" Grid.ColumnSpan="1" Grid.Row="3" Grid.RowSpan="1"
Orientation="Horizontal"
>
<Button
SnapsToDevicePixels="True"
Foreground="{DynamicResource DynamicFrmFG}"
Margin="0,5,5,5"
Content="Download"
Command="{Binding SelectedItem.Content.DownloadCommand, ElementName=filesList}"
MinWidth="50"
>
<!--Command="{Binding SelectedItem.Content.DownloadCommand, Source={StaticResource ResourceKey=filesListTemplate}, ElementName=filesList}"-->
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="{DynamicResource DynamicFrmBGColor}" Offset="0"/>
<GradientStop Color="{DynamicResource DynamicFrmFGColor}" Offset="2"/>
</LinearGradientBrush>
</Button.Background>
</Button>
</StackPanel>
</Grid>
Code snippet for the DataTemplate (The ListView datasource is set to an ObservableCollection and the FilesViewModel contains a Download command):
<DataTemplate x:Key="filesListTemplate">
<ListView
x:Name="filesList"
SnapsToDevicePixels="True"
IsTextSearchEnabled="False"
ItemsSource="{Binding }"
HorizontalContentAlignment="Stretch"
BorderBrush="{DynamicResource DynamicFrmFG}" Foreground="{DynamicResource DynamicFrmFG}" Background="{DynamicResource DynamicFrmBG}"
ItemContainerStyle="{DynamicResource ListViewItemStyle_Gray}"
>
<ListView.View>
<GridView
AllowsColumnReorder="False"
ColumnHeaderContainerStyle="{DynamicResource SpecialityHeader}"
>
<GridViewColumn
Width="200" Header="ID">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock
SnapsToDevicePixels="True"
FontFamily="Consolas" FontSize="14"
Text="{Binding ID}"
/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn
Width="200" Header="File Name">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock
SnapsToDevicePixels="True"
FontFamily="Consolas" FontSize="14"
Text="{Binding Filename}"
/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn
Width="250" Header="Uploaded By">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock
SnapsToDevicePixels="True"
FontFamily="Consolas" FontSize="14"
Text="{Binding Role}"
/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn
Width="200" Header="Uploaded When">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock
SnapsToDevicePixels="True"
FontFamily="Consolas" FontSize="14"
Text="{Binding UploadedWhen}"
/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</DataTemplate>
What I am trying to do is this; Bind the button in my control template to the selected FileViewModel, from the ListView, download command. This command, however, is located up in a DataTemplate. Can someone please assist me in doing this successfully?
Edit at 1705EST: Added the View that calls the control template.
Gridsplitter trouble:
I have a: grid with 4 columns
Column 0 contains a grid with 3 columns
Column 1 contains a gridsplitter
Column 2 contains a stackpanel of width 20 pixels
Column 3 contains a grid with 3 columns
When the gridsplitter is moved to either the left or right, BOTH panels shrink the same amount -- one should shrink and the other should grow.
I am hesitant to include the xaml, but you are going to ask for it, so here is an abridged version. I have only removed a few unrelated controls, and gutted the treeviews and listviews. If you really need the whole thing, then of course I can supply it.
Thanks for any help!
<Window x:Class="Calvin.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Calvin" >
<DockPanel Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" LastChildFill="True" >
<Grid DockPanel.Dock="Top" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" RenderTransformOrigin="0.5,0.497" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" TextWrapping="NoWrap" Text="Field One" HorizontalAlignment="Stretch"/>
<TextBox Grid.Row="0" Grid.Column="4" Grid.ColumnSpan="3" TextWrapping="NoWrap" Text="Field Two" HorizontalAlignment="Stretch" />
<TreeView DockPanel.Dock="Left" Grid.Column="0" Grid.Row="1" Name="PaneOneTree"
Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
</TreeView>
<GridSplitter Grid.Column="1" Grid.Row="1" Width="5" HorizontalAlignment="Center"/>
<ScrollViewer Grid.Column="2" Grid.Row="1" >
<ListView DockPanel.Dock="Left" Name="FileDetailsLeft" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" >
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="120" />
<GridViewColumn Header="Size" Width="120" />
<GridViewColumn Header="Access Time" Width="120" />
<GridViewColumn Header="Extension" Width="120" />
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</Grid>
<GridSplitter Grid.Column="1" Grid.Row="0" Width="5" HorizontalAlignment="Left" />
<StackPanel Grid.Column="2" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Center" Width="Auto" Background="Red">
<Button >Move</Button>
<Button >Other</Button>
</StackPanel>
<Grid Grid.Column="3" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" TextWrapping="NoWrap" Background="Cornsilk"
Text="Pane Two Text" HorizontalAlignment="Stretch"/>
<TextBox Grid.Row="0" Grid.Column="4" Grid.ColumnSpan="3" TextWrapping="NoWrap"
Text="Pane Two Text" HorizontalAlignment="Stretch" Background="Linen" />
<TreeView DockPanel.Dock="Left" Grid.Column="0" Grid.Row="1" Name="PaneTwoTree" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Background="SeaShell" >
</TreeView>
<GridSplitter Grid.Column="1" Grid.Row="1" Width="5" HorizontalAlignment="Center" />
<ScrollViewer Grid.Column="2" Grid.Row="1" >
<ListView DockPanel.Dock="Left" Name="FileDetailsRight"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Background="Moccasin" >
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="120" />
<GridViewColumn Header="Size" Width="120" />
<GridViewColumn Header="Access Time" Width="120" />
<GridViewColumn Header="Extension" Width="120" />
</GridView>
</ListView.View>
<ListViewItem >List Item</ListViewItem>
<ListViewItem >List Item</ListViewItem>
<ListViewItem >List Item</ListViewItem>
<ListViewItem >List Item</ListViewItem>
<ListViewItem >List Item</ListViewItem>
<ListViewItem >List Item</ListViewItem>
<ListViewItem >List Item</ListViewItem>
</ListView>
</ScrollViewer>
</Grid>
</Grid>
</DockPanel>
</Window>
And, of course, feel free to suggest better ways to do anything:) -- I'm still learning.
:bp:
I had the same issue. When I moved one GridSplitter it would also move the other (Usually in the opposite direction.). I eventually discovered that I had forgotten to set a property of the GridSplitter. For a GridSplitter you MUST have both vertical and horizontal properties set ie...
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<GridSplitter Grid.Column="1" Width="2"
VerticalAlignment="Stretch" HorizontalAlignment="Center"/>
</Grid>
Ok, I see your problem now... basically, you can't set an exact Width on a column who's Width will be changed by a GridSplitter control. Instead, you can only set MinWidth and/or MaxWidth property on the ColumnDefinition, but be aware that you can then not use the "*" notation. Also, looking at the code example below, you can see that you could have stripped out a whole load more code for your question example... this was all that was required to demonstrate your problem (before I fixed it):
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="150" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="*" MinWidth="150" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Rectangle Grid.Column="0" Fill="PowderBlue" />
<GridSplitter Grid.Column="1" Background="Black" HorizontalAlignment="Stretch" />
<Rectangle Grid.Column="2" Fill="Red" Height="100" />
<Rectangle Grid.Column="3" Fill="Purple" />
</Grid>
I read a lot about the listView and still cant understand...
I defined the following listView with 5 column, the first is label and the rest are texboxes.
I need to add 13 rows that every textbox and labels needs to be bind to something diffrent.
So I understand that listViewItem wont do it because every object in the list, binds to somethin else..
Thank you for your help.
<ListView DockPanel.Dock="Top" Width="607" Height="400" Margin="10 0" HorizontalAlignment="Left"
ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderThickness="1">
<ListView.View>
<GridView>
<GridViewColumn Header="1" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="2" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="3" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="4" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="5" Width="120" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
you really wane do something like this?
<Grid Height="100" HorizontalAlignment="Left" Margin="22,62,0,0" Name="listBox1" VerticalAlignment="Top" Width="607">
<Grid.ColumnDefinitions>
<ColumnDefinition Width='120'/>
<ColumnDefinition Width='120'/>
<ColumnDefinition Width='120'/>
<ColumnDefinition Width='120'/>
<ColumnDefinition Width='120'/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height='30'/>
<RowDefinition Height='30'/>
</Grid.RowDefinitions>
<!-- ROW 0-->
<Label Grid.Column='0' Grid.Row='0' Content=' your lable' Height="28"/>
<TextBox Grid.Column='1' Grid.Row='0' Text='Text01'/>
<TextBox Grid.Column='2' Grid.Row='0' Text='Text02'/>
<TextBox Grid.Column='3' Grid.Row='0' Text='Text03'/>
<TextBox Grid.Column='4' Grid.Row='0' Text='Text04'/>
<!--Row 1-->
<Label Grid.Column='0' Grid.Row='1' Content=' your lable' Height="28"/>
<TextBox Grid.Column='1' Grid.Row='1' Text='Text01'/>
<TextBox Grid.Column='2' Grid.Row='1' Text='Text02'/>
<TextBox Grid.Column='3' Grid.Row='1' Text='Text03'/>
<TextBox Grid.Column='4' Grid.Row='1' Text='Text04'/>
</Grid>
I finaly did a Grid in every item in the list like this:
<ListView DataContext="{Binding CurrentMonitorCalib}" Grid.Column="5" Grid.Row="3" Height="488" Width="444" ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderThickness="1">
<ListView.View>
<GridView>
<GridViewColumn Header="Cal Point" Width="80"/>
<GridViewColumn Header="Source" Width="90" />
<GridViewColumn Header="Failure Limit" Width="90" />
<GridViewColumn Header="Reference" Width="90" />
<GridViewColumn Header="# DaysLimit" Width="90" />
</GridView>
</ListView.View>
<ListViewItem>
<Grid Width="441" Margin="-359,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="81" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Label Content="Zero" Margin="5,0" />
<TextBox Grid.Column="1" Text="{Binding Path=ZeroSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Column="2" Text="{Binding Path=ZeroFailureLimit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
<TextBox Grid.Column="3" Text="{Binding Path=ZeroRef, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
<TextBox Grid.Column="4" Text="{Binding Path=ZeroZNDays, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" Margin="0,0,8,7" />
</Grid>
</ListViewItem>
<ListViewItem>
<Grid Width="442" Margin="-359,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="81" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
<ColumnDefinition Width="91" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Label Content="Span" Margin="5,0"/>
<TextBox Grid.Column="1" Text="{Binding Path=SpanSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Column="2" Text="{Binding Path=SpanFailureLimit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
<TextBox Grid.Column="3" Text="{Binding Path=SpanRef, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" />
<TextBox Grid.Column="4" Text="{Binding Path=SpanNDays, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}" Margin="0,0,8,7" />
</Grid>
</ListViewItem>
and so on.....
thanks for your help!