How to better present this data in WPF grid? - wpf

I have some data presented in WPF Grid as follows:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="150"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition MinWidth="200"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="5" Style="{StaticResource SectionNumber}" Content="1.3"/>
<Label Grid.Row="1" Grid.Column="0" Margin="5 2">Number of grid in X:</Label>
<Label Grid.Row="1" Grid.Column="1" Margin="5 2">NX</Label>
<lib:NumericTextBox Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" Margin="5 2" Text="{Binding Parameters.NX}"/>
<Label Grid.Row="2" Grid.Column="0" Margin="5 2">Number of grid in Y:</Label>
<Label Grid.Row="2" Grid.Column="1" Margin="5 2">NY</Label>
<lib:NumericTextBox Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2" Margin="5 2" Text="{Binding Parameters.NY}"/>
<Label Grid.Row="3" Grid.Column="0" Margin="5 2">Type of data:</Label>
<Label Grid.Row="3" Grid.Column="1" Margin="5 2">MD</Label>
<ComboBox x:Name="cmbMD" Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" Margin="5 2" SelectedItem="{Binding Data.MD}"/>
<Label Grid.Row="4" Grid.Column="0" Margin="5 2">Data value:</Label>
<Label Grid.Row="4" Grid.Column="1" Margin="5 2">D</Label>
<TextBox Grid.Row="4" Grid.Column="2" Margin="5 2" Text="{Binding Data.D}"/>
<TextBox Grid.Row="4" Grid.Column="3" Margin="5 2" Text="{Binding Unit.LengthUnit, Mode=OneWay}" IsReadOnly="True" />
...
The problem is that I have hundreds of rows to write. In WinForms, I would probably write a user control to present a row of data, and I just need one line of code to create a row.
How can I simplify it here? Can DataTemplate help somehow? I know i can use DataTemplate in a listbox to make it easier. However, I need the columns to be aligned vertically, so I think Grid is the only way to go, right?

WPF ListView or DataGrid is the way to go.
I am writing a simple DataGrid XAML for you.
<DataGrid ItemsSource="{Binding YourCollection}" >
<DataGrid.Columns>
<DataGridTemplateColumn Header="YourColumnHeader1" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Property1}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="YourColumnHeader2" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<lib:NumericTextBox Text="{Binding Property2}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>

It sounds like what you want is a DataGrid, not a Grid.

Related

datepicker issue- calendar size is too big

The following xaml date picker (dropdown) calender and its days width is too big. how to reduce width of calender and days of calender.
Please help me to solve this issue
<Grid Grid.Column="0">
<Grid.ColumnDefinitions >
<ColumnDefinition Width="134"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions >
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Text="Client Name" Grid.Row="0" Grid.Column="0"/>
<TextBox Text="{Binding DataContext.client_name, ElementName=Parant}"
MaxLength="50"
Padding="2"
Height="25"
Grid.Row="0" Grid.Column="1"/>
<TextBlock Text="Building Location" Grid.Row="1" Grid.Column="0"/>
<TextBox MaxLength="255"
Text="{Binding DataContext.location, ElementName=Parant}"
Grid.Row="1"
AcceptsReturn="True"
TextWrapping="Wrap"
Height="40"
Grid.Column="1" />
<TextBlock Text="Date" Grid.Row="2" Grid.Column="0"/>
<!--<TextBox MaxLength="255"
Text="{Binding DataContext.survey_date, ElementName=Parant}"
Grid.Row="2" Grid.Column="1"/>-->
<DatePicker Name="DtpFromDate"
SelectedDate="{Binding DataContext.SurvayDatetime , ElementName=Parant}"
Margin="5"
Width="230"
HorizontalAlignment="Left"
Height="25" Grid.Row="2" Grid.Column="1" />
<!--<TextBlock Text="Edit Lock:" Grid.Row="3" Grid.Column="0"/>
<ComboBox ItemsSource= "{Binding DataContext.elockList, ElementName=Parant}"
SelectedValue="{Binding DataContext.elock, ElementName=Parant}"
Grid.Row="3" Grid.Column="1" />-->
<TextBlock Text="Turn Around Time" Grid.Row="3" Grid.Column="0"/>
<ComboBox ItemsSource="{Binding DataContext.turnaroundList, ElementName=Parant}"
SelectedValue ="{Binding DataContext.turnaround, ElementName=Parant}"
Height ="25"
Grid.Row="3"
Grid.Column="1"/>
please see the picture of calender, and give solution for solve this issue.
My date picker is shown like:
after adding calender custom style the problem solved

Datatemplate binding should work but doesn't. is there an external source for this?

I have a content control that doesn't show the binding data only the static texts:
<ContentControl Name="Detail" Grid.Row="3" Grid.ColumnSpan="3"
ContentTemplate="{StaticResource detailsAdListingTemplate}"
Margin="9,0,0,0"/>
<DataTemplate x:Key="detailsAdListingTemplate" >
<Grid Margin="5,5,5,10">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="113"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Margin="0,0,8,0"
Name="title"
Style="{StaticResource smallTitleStyle}">Title:</TextBlock>
<TextBlock Name="DescriptionDTKey" Grid.Row="0" Grid.Column="1"
Text="{Binding Path=Title}"
Style="{StaticResource textStyleTextBlock}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0,0,8,0"
Name="price"
Style="{StaticResource smallTitleStyle}">Price:</TextBlock>
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
<TextBlock Text="$" Style="{StaticResource textStyleTextBlock}"/>
<TextBlock Name="PriceDTKey"
Text="{Binding Path=Price}"
Style="{StaticResource textStyleTextBlock}"/>
</StackPanel>
<TextBlock Grid.Row="2" Grid.Column="0" Margin="0,0,8,0"
Name="date"
Style="{StaticResource smallTitleStyle}">Date:</TextBlock>
<TextBlock Name="DateDTKey" Grid.Row="2" Grid.Column="1"
Text="{Binding Path=Date}"
Style="{StaticResource textStyleTextBlock}"/>
<TextBlock Grid.Row="3" Grid.Column="0" Margin="0,0,8,0"
Name="subCategory"
Style="{StaticResource smallTitleStyle}">Subcategory: </TextBlock>
<TextBlock Name="SubCategoryDTKey" Grid.Row="3" Grid.Column="1"
Text="{Binding Path=SubCategory.Name}"
Style="{StaticResource textStyleTextBlock}"/>
<TextBlock Grid.Row="4" Grid.Column="0" Margin="0,0,8,0"
Name="owner"
Style="{StaticResource smallTitleStyle}">Owner:</TextBlock>
<TextBlock Name="OwnerDTKey" Grid.Row="4" Grid.Column="1"
Text="{Binding Path=User.Username}"
Style="{StaticResource textStyleTextBlock}"/>
<TextBlock Grid.Row="5" Grid.Column="0" Margin="0,0,8,0"
Name="location"
Style="{StaticResource smallTitleStyle}">Location: </TextBlock>
<TextBlock Name="locationDTKey" Grid.Row="5" Grid.Column="1"
Text="{Binding Path=Location}"
Style="{StaticResource textStyleTextBlock}"/>
<TextBlock Grid.Row="6" Grid.Column="0" Margin="0,0,8,0"
Name="Body"
Style="{StaticResource smallTitleStyle}">Body:</TextBlock>
<TextBlock Name="BodyDTKey" Grid.Row="6" Grid.Column="1"
Text="{Binding Path=Body}"
Style="{StaticResource textStyleTextBlock}"/>
</Grid>
</DataTemplate>
I set the Detail.DataContext=ad; (where ad is a proper Ad object that has all the data and all the properties in the {Binding Path=Property}.
IT USED TO WORK FINE. I don't remember editing it. I don't know what I did to the application but now the data template
only shows the static texts - for example Title: but no actual title.So only the bindings don't work.
I'm sure there is nothing wrong with the xaml code above and it should work.
Is there an "external" other source that may be causing this problem?
ContentTemplate is the template used to display ContentControl.Content, which you are leaving as null
Either set Detail.Content = ad; (instead of Detail.DataContext), or bind your ContentControl.Content property to the current DataContext.
<ContentControl Name="Detail" Grid.Row="3" Grid.ColumnSpan="3" Margin="9,0,0,0"
Content="{Binding }"
ContentTemplate="{StaticResource detailsAdListingTemplate}" />

Grid with DataContext of DataView won't display data after DataTable.Clear and DataAdapter.Fill

I'll apologize in advance for a long post. I have two DataTables (Cases and Jobs), each with a DataView that I bind my GUI to (the Cases dataview is the DataContext for a Grid, while the Jobs dataview is the ItemsSource of a ListView and the DataContext of a TabControl). The first time I fill the tables with DataAdapter.Fill, the data shows properly for cases and jobs. The second time I load data, I call DataTable.Clear and then DataAdapter.Fill, but only the jobs data shows in the GUI. The case data is nowhere to be seen, even though stepping through I can tell there's a row in the DataTable with the correct data. That is, the DataTable.Clear and DataAdapter.Fill work properly; the Grid control in my GUI just doesn't show the data. I've copied the XAML for the Grid control below. Can anyone help me?! Thanks.
UPDATE: If I have more than one row in the table the second time around, data shows up in the text boxes properly! What the hell is going on?
<Grid Height="165" Width="390" DataContext="{Binding caseTableView}" >
<Grid.Resources>
<local:CaseStatusItemsSource x:Key="StatusesSource" />
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="10" />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition Height="10" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120" />
<ColumnDefinition Width="120" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<!--Case Details-->
<Label Style="{StaticResource LabelStyle}" Grid.Row="1" Grid.Column="1" >Case Number:</Label>
<TextBox Grid.Row="1" Grid.Column="2" Style="{StaticResource TextBoxStyle}" IsReadOnly="{Binding isROCaseNumber}" LostFocus="caseNumber_LostFocus" >
<TextBox.Text>
<Binding Path="/CASENUMBER" UpdateSourceTrigger="LostFocus">
<Binding.ValidationRules>
<local:CaseNumberValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<Label Style="{StaticResource LabelStyle}" Grid.Row="2" Grid.Column="1" >Date Received:</Label>
<TextBox Grid.Row="2" Grid.Column="2" Style="{StaticResource TextBoxStyle}" Text="{Binding Path=/DATERECEIVED, StringFormat=d}" IsReadOnly="{Binding isRODateReceived}" />
<Label Style="{StaticResource LabelStyle}" Grid.Row="3" Grid.Column="1" >Status:</Label>
<ComboBox Grid.Row="3" Grid.Column="2" Width="140" Height="20" HorizontalAlignment="Left" FontFamily="Verdana" FontSize="9"
ItemsSource="{Binding statuses, Source={StaticResource StatusesSource}}" SelectedItem="{Binding Path=/STATUS, Mode=TwoWay}" IsReadOnly="{Binding isROCaseStatus}" >
</ComboBox>
<Label Style="{StaticResource LabelStyle}" Grid.Row="4" Grid.Column="1" >Date Ord. Received:</Label>
<TextBox Grid.Row="4" Grid.Column="2" Style="{StaticResource TextBoxStyle}" Text="{Binding Path=/DATEORDRECEIVED, StringFormat=d}" IsReadOnly="{Binding isRODateOrdReceived}" />
<Label Style="{StaticResource LabelStyle}" Grid.Row="5" Grid.Column="1" >Date Posted:</Label>
<TextBox Grid.Row="5" Grid.Column="2" Style="{StaticResource TextBoxStyle}" Text="{Binding Path=/DATEPOSTED, StringFormat=d}" IsReadOnly="{Binding isRODatePosted}" />
</Grid>
There has to be a bug in Microsoft's code somewhere, because I fixed it with the code shown below.
ICollectionView _cv = CollectionViewSource.GetDefaultView(_appModel.casesTable);
_cv.MoveCurrentToNext();
I only needed to do this for the case table, not the jobs table, which is why I expect there's a bug somewhere. The jobs table always worked whether there was one or more than one row in the table.

Can't get WPF Listview to collapse when expanders in the listview collapse

I have a wpf ListView with two Expanders in it. When the expanders expand the listview makes room for the content. When they collapse the listview does not "take back" that extra space. I have set HorizontalAlignment and VerticalAlignment to Stretch everywhere. Is there a way to do this? The Details and Chart columns contain the expanders. See code below. Thanks.
Here at
<Window.Resources>
<DataTemplate x:Key="StockPriceChangeCell">
<StackPanel Orientation="Horizontal">
<Label Name="stockPriceChangeValue" Foreground="{Binding StockPriceChangeColor}" Content="{Binding StockPriceChange}" Width="Auto"></Label>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="DetailsCell">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Expander Header="Details..." BorderBrush="DarkBlue" Width="200" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid Name="stockDetailGrid" Background="Beige" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ShowGridLines="False">
<Grid.RowDefinitions>
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="96*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
<RowDefinition Height="6*" />
<RowDefinition Height="96*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Name="previousClosePrompt" FontWeight="Bold" FontSize="12" Height="28" Width="Auto">Prev Close:</Label>
<Label Grid.Row="0" Grid.Column="1" Name="previousCloseValue" FontWeight="Bold" FontSize="12" Height="28" Width="Auto" Content="{Binding StockDetails.PreviousClose}"></Label>
<Separator Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator3" Margin="0,2" />
<Label Grid.Row="2" Grid.Column="0" Name="openPricePrompt" FontWeight="Bold" FontSize="12" Height="28">Open:</Label>
<Label Grid.Row="2" Grid.Column="1" Name="openPriceValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.OpeningPrice}"></Label>
<Separator Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator5" Margin="0,2" />
<Label Grid.Row="4" Grid.Column="0" Name="yearlyTargetEstimatePrompt" FontWeight="Bold" FontSize="12" Height="28">1y Target Est:</Label>
<Label Grid.Row="4" Grid.Column="1" Name="yearlyTargetEstimateValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.YearTargetEstimate}"></Label>
<Separator Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator6" Margin="0,2" />
<Label Grid.Row="6" Grid.Column="0" Name="stockDaysRangePrompt" FontWeight="Bold" FontSize="12" Height="28">Day's Range:</Label>
<Label Grid.Row="6" Grid.Column="1" Name="stockDaysRangeValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.DaysRange}"></Label>
<Separator Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator7" Margin="0,2" />
<Label Grid.Row="8" Grid.Column="0" Name="stockYearsRangePrompt" FontWeight="Bold" FontSize="12" Height="28">52wk Range:</Label>
<Label Grid.Row="8" Grid.Column="1" Name="stockYearsRangeValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.YearsRange}"></Label>
<Separator Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator8" Margin="0,2" />
<Label Grid.Row="10" Grid.Column="0" Name="averageVolumePrompt" FontWeight="Bold" FontSize="12" Height="28">Avg Vol (3m):</Label>
<Label Grid.Row="10" Grid.Column="1" Name="averageVolumeValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.AverageVolume}"></Label>
<Separator Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator9" Margin="0,2" />
<Label Grid.Row="12" Grid.Column="0" Name="marketCapPrompt" FontWeight="Bold" FontSize="12" Height="28">Market Cap:</Label>
<Label Grid.Row="12" Grid.Column="1" Name="marketCapValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.MarketCap}"></Label>
<Separator Grid.Row="13" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator10" Margin="0,2" />
<Label Grid.Row="14" Grid.Column="0" Name="priceEarningRatioPrompt" FontWeight="Bold" FontSize="12" Height="28">P/E (ttm):</Label>
<Label Grid.Row="14" Grid.Column="1" Name="priceEarningRatioValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.PriceEarningsRatio}"></Label>
<Separator Grid.Row="15" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator11" Margin="0,2" />
<Label Grid.Row="16" Grid.Column="0" Name="earningsPerSharePrompt" FontWeight="Bold" FontSize="12" Height="28">EPS (ttm):</Label>
<Label Grid.Row="16" Grid.Column="1" Name="earningsPerShareValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.EarningsPerShare}"></Label>
<Separator Grid.Row="17" Grid.Column="0" Grid.ColumnSpan="2" Name="stockSeparator12" Margin="0,2" />
<Label Grid.Row="18" Grid.Column="0" Name="dividendYieldPrompt" FontWeight="Bold" FontSize="12" Height="28">Div & Yield:</Label>
<Label Grid.Row="18" Grid.Column="1" Name="dividendYieldValue" FontWeight="Bold" FontSize="12" Height="28" Content="{Binding StockDetails.DividendYield}"></Label>
</Grid>
</Expander>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="ChartCell">
<StackPanel>
<Expander Header="Chart..." BorderBrush="DarkBlue" Width="200" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Image Name="stockGraph" Stretch="None" Source="{Binding StockChart}"/>
</Expander>
</StackPanel>
</DataTemplate>
</Window.Resources>
Here is the listview:
<TabItem Name="myStocksTab" Header="My Stocks" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<StackPanel Name="myStocksTabContainerPanel" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Label Name="myStocksPrompt" Foreground="GhostWhite" Background="DarkBlue" FontSize="16" FontWeight="Bold">My Stocks</Label>
<ListView Name="stocksUIList" ItemsSource="{Binding}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch">
<ListView.View>
<GridView>
<GridViewColumn Header="Action" CellTemplate="{StaticResource ButtonsCell}" Width="Auto"/>
<GridViewColumn Header="Company/Stock Symbol" Width="Auto" DisplayMemberBinding="{Binding CompanyName}"/>
<GridViewColumn Header="Last Trade" Width="Auto" DisplayMemberBinding="{Binding LastTrade}"/>
<GridViewColumn Header="Trade Time" Width="Auto" DisplayMemberBinding="{Binding StockDetails.TradeTime}"/>
<GridViewColumn Header="Change" CellTemplate="{StaticResource StockPriceChangeCell}"/>
<GridViewColumn Header="Volume" Width="Auto" DisplayMemberBinding="{Binding TradingVolume}"/>
<GridViewColumn Header="Details" CellTemplate="{StaticResource DetailsCell}" Width="215"/>
<GridViewColumn Header="Chart" CellTemplate="{StaticResource ChartCell}" Width="215"/>
</GridView>
</ListView.View>
</ListView>
<Button Name="addStock" FontSize="14" FontWeight="Bold" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Click="AddCompanyStock">Add Stock...</Button>
</StackPanel>
I know this is an older post, but I was looking for a solution to this problem and wanted to update it with my solution.
After some searching I was able to fix it by using the solution found here: ListView with nested Expander not collapsing
Basically I was using a ListView with Expanders in the Item Template. When collapsing the expander would not resize properly. Also when the expander content was larger than the ListView, the scroll would not work properly.
The fix was simply replacing ListView with ItemsControl and putting the ItemsControl inside a ScrollViewer.
It sounds like there may be a layout bug of sorts in the ListView. Have you tried calling InvalidateVisual() on the ListView in the Collapsed event of either of the expanders? That may do the trick.

WPF ListBox: how to update data with binding

I have listbox that displays information about list of objects:
<ListBox Grid.Column="0" Height="152" Name="CustomersList" HorizontalAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name, Mode=OneWay}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I would show more detailed information about selected item in another block, but I don't know (and can't find) how to bind selected item to those block data context. I guess it should be something like this:
<Grid Grid.Column="1" DataContext="{Binding Path=ItemSelected, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="250"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Id" VerticalAlignment="Center" />
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path=Id}" VerticalAlignment="Center"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Name" VerticalAlignment="Center"/>
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=Name}" VerticalAlignment="Center"/>
<StackPanel Grid.Row="2" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Content="Add new" />
<Button Content="Store changes" />
</StackPanel>
</Grid>
But the problem is that data item to be binded to the grid is not specified anywhere and I don't know how to do that.
Any suggestion would be wellcome.
Thanks!
P.S. I've tried to specify CustomersList.ItemsSource as DataContext for the Grid - this didn't give any result.
You can bind to the SelectedItem property of the ListBox, one way is using ElementName.
<Grid DataContext="{Binding ElementName=CustomersList, Path=SelectedItem}"> </Grid>

Resources