Can't bind child collection in silverlight - silverlight

I have a pretty simple setup that I cannot get to work in silverlight. I have an order with a collection of OrderPayments. These objects are part of a Entity Framework model and are exposed through WCF RIA Services. I can bind perfectly fine to any basic property on the Order class, but I wanted to bind to a listbox to show the OrderPayments. Here's the XAML for the ListBox.
<ListBox ItemsSource="{Binding Data.OrderPayments, ElementName=orderDataSource}"></ListBox>
Nothing ever appears in the listbox and there is at least one OrderPayment for the order displayed. orderDataSource is a DomainDataSource that contains the Order. The odd thing about this is that I don't receive any binding errors and when I bind to a TextBlock using the following code:
<TextBlock Text="{Binding Data.OrderPayments, ElementName=orderDataSource}" />
The text 'OrderPayment' is outputted to the screen. Is there something different I have to do to get Silverlight to actually pick up the reference to the object?
Entire XAML below:
<riaControls:DomainDataSource AutoLoad="True" Name="orderDataSource" QueryName="GetOrder">
<riaControls:DomainDataSource.QueryParameters>
<riaControls:Parameter ParameterName="orderid" Value="1" />
</riaControls:DomainDataSource.QueryParameters>
<riaControls:DomainDataSource.DomainContext>
<ds:CEWCPSDomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<StackPanel Orientation="Vertical" Margin="12">
<StackPanel Orientation="Horizontal">
<Button Width="100" Height="50" Content="Save & Return" Margin="0,0,12,12" />
<Button Width="100" Height="50" Content="Orders" Margin="0,0,12,12" />
<Button Width="100" Height="50" Content="Emails" Margin="0,0,12,12" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<dataForm:DataForm x:Name="dataForm1" Header="Order Contact Information"
AutoGenerateFields="False" AutoEdit="False" AutoCommit="False"
CurrentItem="{Binding Data, ElementName=orderDataSource}">
<dataForm:DataForm.EditTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel>
<dataForm:DataField Label="First Name">
<TextBox Text="{Binding FirstName, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }" />
</dataForm:DataField>
<dataForm:DataField Label="Last Name">
<TextBox Text="{Binding LastName, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="Organization">
<TextBox Text="{Binding Organization, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="Phone">
<TextBox Text="{Binding Phone, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="Fax">
<TextBox Text="{Binding Fax, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="Email">
<TextBox Text="{Binding Email, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="Address 1">
<TextBox Text="{Binding Address1, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="Address 2">
<TextBox Text="{Binding Address2, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="City">
<TextBox Text="{Binding City, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="State">
<TextBox Text="{Binding State, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<StackPanel Orientation="Horizontal" Width="Auto">
<dataForm:DataField Label="Zip code">
<TextBox Text="{Binding Zip, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField>
<TextBox Text="{Binding Zip4, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
</StackPanel>
<dataForm:DataField Label="Country">
<TextBox Text="{Binding Country, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
</StackPanel>
</StackPanel>
</DataTemplate>
</dataForm:DataForm.EditTemplate>
</dataForm:DataForm>
<StackPanel Orientation="Vertical">
<TextBlock FontWeight="Bold" FontSize="16" Text="Order Total / Payments" />
<TextBlock >
<Run Text="Order Total:" />
<Run Text="{Binding Data.OrderTotal, ElementName=orderDataSource}" />
</TextBlock>
<TextBlock Text="Payments" />
<TextBlock Text="{Binding Data.OrderPaymentItems, ElementName=orderDataSource}" />
<ListBox ItemsSource="{Binding Data.OrderPayments, ElementName=orderDataSource}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Amount}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</StackPanel>
</StackPanel>

WCF RIA Services does not include child entities by default. I needed to put [Include()] on the OrderPayments property of the Order object. Works like a charm now.

Related

TextBox in RadGridViewColumn IN WPF

There is a textbox in the gridviewColumn And a ComboBox in the other column In need to set the TextBox read only true and readOnly False On the section On COmboBox.
<telerik:GridViewDataColumn x:Name="requstamount" Header="Request Amount" Width="200">
<telerik:GridViewColumn.CellTemplate >
<DataTemplate>
<TextBox IsEnabled="{Binding IsTextBoxEnabled, StringFormat=c, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Name="txtPaymentAMNT"
Text="{Binding PaymentAmount, StringFormat=c, UpdateSourceTrigger=PropertyChanged}"
Background="Transparent"
LostFocus="text_LostFocus"
BorderBrush="LightGray"
BorderThickness="0,0,0,3"
Width="141"
Margin="-5,0,0,0" />
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Header="Request Type" Width="150">
<telerik:GridViewColumn.CellTemplate >
<DataTemplate>
<telerik:RadComboBox x:Name="cboType"
Background="Transparent"
HorizontalAlignment="Left"
BorderBrush="blue"
BorderThickness="0,0,0,1"
Margin="-5,0,0,0"
telerik:StyleManager.Theme="Office2019"
Width="100"
Height="25"
SelectedIndex="{Binding Path=Reqsttype, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectionChanged="cmbType_SelectionChanged"
SelectedValuePath="{Binding OrderNo}">
<telerik:RadComboBoxItem Name="Pre_Auth" IsSelected="True">
Pre-Auth
</telerik:RadComboBoxItem>
<telerik:RadComboBoxItem Name="Deposit">
Deposit
</telerik:RadComboBoxItem>
</telerik:RadComboBox>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewDataColumn>

ListBoxEditItem Visibility not working as expected

I have the following xaml and I am trying to set the ListBoxEditItem for Content="3" without using the ElementName for ck because I want to set the Visibility directly and not have the CheckBox. Why does the Visibility work for Content="2" ListBoxEditItem and not Content="3"? How do I set the Visibility directly?
<StackPanel>
<dxe:ComboBoxEdit EditValue="{Binding test, UpdateSourceTrigger=PropertyChanged}">
<Visibility>Visible</Visibility>
<Visibility>Collapsed</Visibility>
<Visibility>Hidden</Visibility>
</dxe:ComboBoxEdit>
<dxe:ListBoxEdit StyleSettings="{dxe:RadioListBoxEditStyleSettings}">
<dxe:ListBoxEditItem Content="1" />
<dxe:ListBoxEditItem Content="2" Visibility="{Binding Visibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ElementName=ck}" />
<dxe:ListBoxEditItem Content="3" Visibility="{Binding test, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</dxe:ListBoxEdit>
<CheckBox x:Name="ck" Visibility="{Binding test, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Text="some stuff" Visibility="{Binding Visibility, ElementName=ck}" />
</StackPanel>
I needed DataContext in the binding like so:
<dxe:ListBoxEditItem Content="3" Visibility="{Binding DataContext.test, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

WPF:- How to create a Treeview control with combo box, check box and text box in it using MVVM

I'm trying to put a ComboBox, a checkbox and a few textboxes inside a treeview in WPF.
Following is the basic structure of the treeview requirement
-Parent
--Label Textbox
--Label Textbox
--Label Textbox
--Label Combo box
--Label Check box
--Payload
---Label
----Label Textbox
----Label Combobox
----Label Textbox
Following is the xaml code
<TreeView x:Name="BTreeView" Grid.Column="1" Grid.Row="1" Margin="1,10,0,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding TreeViewListings}" >
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type viewmodel:TreeViewBViewModel}" ItemsSource="{Binding Positions}" >
<TextBlock Text="Level1"/>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding PayLoadList}" DataType="{x:Type viewmodel:Position}">
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Text 1" />
<TextBox Text="{Binding Path=Text1, UpdateSourceTrigger=PropertyChanged}" Width="200" Margin="10,0,0,0" BorderThickness="0" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Text 2" />
<TextBox Text="{Binding Path=Text1, UpdateSourceTrigger=PropertyChanged}" Width="200" Margin="10,0,0,0" BorderThickness="0" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Text 3"/>
<ComboBox Width="100" Height="18" Margin="10,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="10" IsEditable="True" IsReadOnly="True" BorderThickness="0">
<ComboBoxItem IsSelected="True">Item 1</ComboBoxItem>
<ComboBoxItem>Item 2</ComboBoxItem>
<ComboBoxItem>Item 3</ComboBoxItem>
<ComboBoxItem>Item 4</ComboBoxItem>
<ComboBoxItem>Item 5</ComboBoxItem>
</ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Canvas.Left="10" Canvas.Top="10" Content="Active" IsChecked="False"/>
</StackPanel>
<TextBlock Text="{Binding PayLoadText}"/>
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding PayLoadData}" DataType="{x:Type viewmodel:Payload}">
<Label Content="{Binding FieldName}"/>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate DataType="{x:Type viewmodel:PayloadData}">
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Text 4" />
<TextBox Text="{Binding Path=Text4, UpdateSourceTrigger=PropertyChanged}" Width="200" Margin="10,0,0,0" BorderThickness="0" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Data}" />
<TextBox Text="{Binding Path=DataFieldValue, UpdateSourceTrigger=PropertyChanged}" Width="200" BorderThickness="0" HorizontalAlignment="Left"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Operation" />
<ComboBox Width="100" Height="18" Margin="10,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="10" IsEditable="True" IsReadOnly="True" BorderThickness="0">
<ComboBoxItem>Item 1</ComboBoxItem>
<ComboBoxItem>Item 2</ComboBoxItem>
<ComboBoxItem>Item 3</ComboBoxItem>
<ComboBoxItem>Item 4</ComboBoxItem>
</ComboBox>
</StackPanel>
</StackPanel>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
I am using MVVM architectural pattern to achieve this goal. The problem that I am facing is with the arrow head of second level node. It is not aligned at the right position. The arrowhead gets automatically aligned to "Text3" combo box instead of "Payload" node. Following is the image of my tree view
I do not know if there is any other approach to include Combo box, check box, text boxes inside a treeview using MVVM approach. Would appreciate if you let me know your approach of designing this treeview

How do I put a header on the ItemsControl?

I want to show a product list with a header like a DataGrid. But I don't know how to show heading in the listbox.
<ListBox ItemsSource="{Binding CustomSalesProducts, Mode=TwoWay}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Template="{DynamicResource ListBox}" Style="{DynamicResource ListBoxStyle1}" BorderBrush="{DynamicResource BorderBrush}" Foreground="{DynamicResource ForegroundBrush}" FontFamily="Palatino Linotype" FontSize="13.333" ItemContainerStyle="{DynamicResource ListBoxItemStyle}" SelectedValue="{Binding CurrentCustomSale, Mode=TwoWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel CanHorizontallyScroll="True" CanVerticallyScroll="True" Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding ProductName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="{StaticResource Margin4}" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Quantity" KeyUp="TextBox_KeyUp"/>
<TextBox Text="{Binding OrderQty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="{StaticResource Margin4}" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Quantity" KeyUp="TextBox_KeyUp">
</TextBox>
<TextBox Text="{Binding UnitSalePrice, Mode=TwoWay}" Style="{DynamicResource MiniTextBoxStyle}" Margin="{StaticResource Margin4}" ToolTip="Price" IsReadOnly="True" />
<TextBox Text="{Binding MainDiscount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="{StaticResource Margin4}" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Discount" KeyUp="TextBox_KeyUp"/>
<TextBox Text="{Binding Discount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="{StaticResource Margin4}" IsReadOnly="True" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Line Discount" KeyUp="TextBox_KeyUp"/>
<TextBox Text="{Binding TaxAmount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="{StaticResource Margin4}" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Tax Amount" IsReadOnly="True" />
<TextBox Text="{Binding LineTotal, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="{StaticResource Margin4}" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Total" IsReadOnly="True" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
I want this kind of output
--------------------------------------
ID Name Price Discount
1 xxxx 1245 8
2 xxxxxxxx 4354 9
..... and so on..
I think what you really whant is a ListView with a GridView view.
<ListView ItemsSource="{Binding Source=
{StaticResource EmployeeInfoDataSource}}">
<ListView.View>
<GridView AllowsColumnReorder="true"
ColumnHeaderToolTip="Employee Information">
<GridViewColumn DisplayMemberBinding=
"{Binding Path=FirstName}"
Header="First Name" Width="100"/>
<GridViewColumn DisplayMemberBinding=
"{Binding Path=EmployeeNumber}"
Header="Employee No." Width="100"/>
</GridView>
</ListView.View>
</ListView>

Telerik RadComboBox not showing Selected Item

I have a RadComboBox that i have bound like shown below
<telerik1:RadComboBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" Margin="5,2" ItemsSource="{Binding RepTypes}" DisplayMemberPath="Path=TypeName" SelectedValuePath="Value" SelectedItem="{Binding RepType, Mode=TwoWay}" >
</telerik1:RadComboBox>
When i select an Item I catch the Property Changed event, but basically the selection in the combo box stays blank.
What am i doing wrong?
Ok i made it so that it shows up now.. But i don't understand why... Or how to change it so it works for me in all cases...
<telerik1:RadComboBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" Margin="5,2" ItemsSource="{Binding RepTypes}" SelectedValuePath="Value" SelectedItem="{Binding RepType, Mode=TwoWay}" >
</telerik1:RadComboBox>
Thats what works... the Biggest difference was. I had to name a field to "Name" and then bind it and take out the DisplayMemberPath="Path=ReportName"
If that is the case then how do i tell the control what Field to Display in the dropdown?
Are you somehow changing your collection? The controls only look for the items once. So, if the page loads and then you're loading your collection of RepTypes, it doesn't update the dictionary. I'm doing something similar and I'm lazy loading my collection (as you type, I get more from the database).
<t:RadComboBox x:Name="RepTypeComboBox" Margin="0,1"
t:TextSearch.TextPath="TypeName"
ItemsSource="{Binding Path=RepTypes, Mode=OneWay}"
SelectedValue="{Binding Path=Reptype, Mode=TwoWay, NotifyOnValidationError=True}"
IsEditable="True"
Grid.Column="1"
Grid.Row="2" TabIndex="1">
<t:RadComboBox.ItemTemplate >
<DataTemplate >
<StackPanel Orientation="Horizontal" >
<TextBlock FontWeight="Bold" Text="{Binding Path=TypeName, Mode=OneWay}" Width="75"/>
<TextBlock Text=": " />
<TextBlock Text="{Binding Path=address1, Mode=OneWay}" />
<TextBlock Text=" " />
<TextBlock Text="{Binding Path=address2, Mode=OneWay}" />
<TextBlock Text=" " />
<TextBlock Text="{Binding Path=citystate, Mode=OneWay}" />
<TextBlock Text=" " />
<TextBlock Text="{Binding Path=zip, Mode=OneWay}" />
</StackPanel>
</DataTemplate>
</t:RadComboBox.ItemTemplate>
</t:RadComboBox>
If you want ReportName to be shown as your display member, you only have to put it this way:
<telerik1:RadComboBox ItemsSource="{Binding RepTypes}" SelectedValuePath="Value"
SelectedItem="{Binding RepType, Mode=TwoWay}" DisplayMemberPath="ReportName">
</telerik1:RadComboBox>
You're putting an extra "Path=" that's only confusing the XAML parser.

Resources