Note that there are some explanatory texts on larger screens.

plurals
  1. PORelated table declarative databinding in wpf/xaml
    text
    copied!<p>I have been working through a very small-scale WPF project in order to familiarize myself with it while I read Nathan's book. I am attempting to do declarative binding on a single window with multiple tables from the same dataset. The schema (names have been changed to protect the innocent) is: tblMany2--tblOne--tblMany1</p> <p>XAML is below, but in short:</p> <ul> <li>I set the datacontext in the windows _loaded handler. I have tried both to the dataset and to the table which is the primary table conceptually (tblMany1).</li> <li>I set the ItemSource on a combo box to tblMany1.</li> <li>I set the ItemSource on a second combo box to the foreign key data relation (originally it was a tbo, but I've been working for a while).</li> <li>The idea is to control the second combo box (and other controls) by changing the first.</li> <li>The result so far is a blank entry in the second combobox with a debug output saying cannot find the property of whichever object I've set the ItemsSource to.</li> </ul> <p><strong>XAML:</strong></p> <pre><code>&lt;Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace;system;assembly=mscorlib" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:my="clr-namespace:MyProject" xmlns:dx="clr-namespace:System.Diagnostics;assembly=WindowsBase" Height="500" Width="700" d:DesignHeight="350" d:DesignWidth="525" SizeToContent="WidthAndHeight"&gt; &lt;Window.Resources&gt; &lt;!--Data--&gt; &lt;!--Styles--&gt; &lt;Style x:Key="buttonStyle"&gt; &lt;Setter Property="Button.Width" Value="85" /&gt; &lt;Setter Property="Button.Height" Value="30" /&gt; &lt;/Style&gt; &lt;Style x:Key="chkImageStyle" TargetType="Image"&gt; &lt;Setter Property="Image.Height" Value="25" /&gt; &lt;Setter Property="Image.Width" Value="30" /&gt; &lt;Setter Property="Image.Margin" Value="100,30,0,0" /&gt; &lt;Setter Property="Image.Stretch" Value="Fill" /&gt; &lt;Setter Property="Image.VerticalAlignment" Value="Top" /&gt; &lt;Setter Property="Grid.Column" Value="1" /&gt; &lt;Setter Property="Image.Source" Value="checkmark.jpg" /&gt; &lt;Setter Property="Image.Visibility" Value="hidden" /&gt; &lt;/Style&gt; &lt;!--Data Tempaltes--&gt; &lt;DataTemplate x:Key="tblMany1Date"&gt; &lt;TextBlock Text="{Binding Path=tblMany1Date, StringFormat=d,dx:PresentationTraceSources.TraceLevel=High}" /&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="tblOneLink"&gt; &lt;TextBlock HorizontalAlignment="Center"&gt; &lt;Hyperlink NavigateUri="{Binding Path=tblOne.Link}"&gt; &lt;Run Text="{Binding Path=tblOne.Name}" /&gt; &lt;/Hyperlink&gt; &lt;/TextBlock&gt; &lt;/DataTemplate&gt; &lt;/Window.Resources&gt; &lt;Viewbox Stretch="Uniform" Height="500" Width="750"&gt; &lt;!-- Main Dockpanel--&gt; &lt;DockPanel Name="DockPanel1"&gt; &lt;!-- NavPane --&gt; &lt;StackPanel Height="315" Background ="LightBlue" DockPanel.Dock="Left" Name="StackPanel1" Width="135"&gt; &lt;Button Margin="5" Content="New" Name="btnNewOne" Style="{StaticResource buttonStyle}"/&gt; &lt;Label Margin="0" Content="ManyDate:" Name="lblDate" /&gt; &lt;!--Primary Control--&gt; &lt;ComboBox Margin ="0" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=tblMany1}" ItemTemplate="{StaticResource tblMany1Date}" Height="23" Name="cboDate" Width="120" ForceCursor="False" AllowDrop="False" /&gt; &lt;TextBlock Margin="-5" Visibility="Hidden"/&gt; &lt;Label Margin="0" Content="OneName:" Name="lblOneName" /&gt; &lt;ComboBox Margin="0" ItemsSource="{Binding FK_tblMany1_tblOne}" ItemTemplate="{StaticResource tblOneLink}" Name="cboOne" /&gt; &lt;/StackPanel&gt; &lt;/DockPanel&gt; &lt;/Viewbox&gt; </code></pre> <p></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload