Telerik RadComboBox not showing Selected Item - silverlight

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.

Related

Binding a string doesn't show up, Binding another type does... WPF

I just started with WPF and databinding. First question on databinding.
Databinding on {Binding Periode.Einde} where Einde is of type DateTime works,
{Binding Arrangement} where Arrangement is of type Enum works, {Binding Limo.Info} where Info is of type String doesn't work.
Somebody has an explanation for that?
<ListView Grid.Column="3" Grid.Row="3" Name="hups" Background="{x:Null}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel>
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Background="BlueViolet" Opacity="80" DockPanel.Dock="Left">
<Image Source="images\limousine-car-VIP-transport-128.png" Height="50"/>
<StackPanel>
<TextBlock Text="Starttijdstip:" />
<TextBlock Text="{Binding Periode.Begin, ConverterCulture='nl-BE', StringFormat='dddd, dd MMMM yyyy HH:mm:ss'}" FontWeight="Bold" />
<TextBlock Text="Stoptijdstip:" />
<TextBlock Text="{Binding Periode.Einde, ConverterCulture='nl-BE', StringFormat='dddd, dd MMMM yyyy HH:mm:ss'}" FontWeight="Bold" />
</StackPanel>
</StackPanel>
<StackPanel DockPanel.Dock="Right" Background="BlueViolet" HorizontalAlignment="Right">
<TextBlock Text="Limo:" />
<TextBlock Text="{Binding Limo.Info}" FontWeight="Bold" />
<TextBlock Text="Arrangement:" />
<TextBlock Text="{Binding Arrangement}" FontWeight="Bold" />
</StackPanel>
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
In your binding expression Text="{Binding Limo.Info}" then if Limo.Info is of type string, then there are only 3 possible scenarios as to why nothing appears in your UI
1) Limo object is null
2) Info string is null or empty
3) Limo.Info is spelled incorrectly, and it's actually something else.
It has to be one of those 3 scenarios. check the objects you are passing into your ListView
Indeed Limo is null. It's Entity Framework with Lazy Loading I think...

How to do text search in DropDown of ComboBox with IsEditable=false

I have a ComboBox with IsEditable = false. When the user drops down the list, I'd like to support him in searching for the right item, by scrolling to the first item that fits to a letter the user types.
So when the DropDown is open and the user types 'S', I'd like him to scroll to the first item (in my case: customer) whose name starts with 'S'.
I can't use the built-in text search because the ComboBox's IsEditable is false. The user can only select one of the proposed values (customers).
How can I do text search anyway? Here is my code:
<ComboBox x:Name="cmbCustomer"
ItemsSource="{Binding LstAllCustomers, Mode=TwoWay}"
SelectedItem="{Binding SelectedCustomer, Mode=TwoWay}"
ItemContainerStyle="{StaticResource customerListStyle}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="2" Text="{Binding ID}"/>
<TextBlock Margin="2" Text="{Binding LastName}"/>
<TextBlock Margin="2" Text="{Binding FirstName}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Set the IsTextSearchEnabled property to true and the TextSearch.TextPath attached property to either "LastName" or"FirstName" or whatever your property is called:
<ComboBox x:Name="cmbCustomer"
ItemsSource="{Binding LstAllCustomers, Mode=TwoWay}"
SelectedItem="{Binding SelectedCustomer, Mode=TwoWay}"
ItemContainerStyle="{StaticResource customerListStyle}"
IsTextSearchEnabled="True" TextSearch.TextPath="LastName">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="2" Text="{Binding ID}"/>
<TextBlock Margin="2" Text="{Binding LastName}"/>
<TextBlock Margin="2" Text="{Binding FirstName}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
This should work even if you don't set the IsEnabled property to true, assuming that your Customer class actually has a LastName property.

Getting selected item from Treeview

I have a TreeView and want to get the selected item from it.
The Treeview itself is populated not manually, but from data in the code. Since it is populated this way, I'm not sure how to get information out of it.
Here is the XAML:
<TreeView Name="trvFamilies" HorizontalAlignment="Left" Margin="10,10,3,3" Width="340">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type self:Scene}" ItemsSource="{Binding Characters}">
<StackPanel Orientation="Horizontal">
<StackPanel.ContextMenu>
<ContextMenu>
<MenuItem Header="New" Click="MenuItem_Click"></MenuItem>
<MenuItem Header="Remove" Click="MenuItem_Click_1"></MenuItem>
</ContextMenu>
</StackPanel.ContextMenu>
<Image Source="{StaticResource ImageSceneRegular}" Margin="0,0,5,0" Width="64" Height="64"/>
<TextBlock Text="{Binding Name}" />
<TextBlock Text=" [" Foreground="Blue" />
<TextBlock Text="{Binding Characters.Count}" Foreground="Blue" />
<TextBlock Text="]" Foreground="Blue" />
</StackPanel>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type self:Character}">
<Border BorderThickness="1" Background="AliceBlue" CornerRadius="8,8,3,3">
<StackPanel Orientation="Horizontal" Margin="4" Background="White">
<Image Source="{Binding Img}" Margin="0,0,5,0" Width="64" Height="64" />
<TextBlock Text="{Binding Name}" />
<TextBlock Text=" (" Foreground="Green" />
<TextBlock Text="{Binding Age}" Foreground="Green" />
<TextBlock Text=" years)" Foreground="Green" />
</StackPanel>
</Border>
</DataTemplate>
</TreeView.Resources>
</TreeView>
It is populated by data from an ObservableCollection which is populated within the code and then assigned to the ItemSource of the treeview (and it works fine).
So let's say I had a TextBlock which sat outside the TreeView and wanted to populate it with information from the selected Character (that's the type which populates the drop down part of the TreeView), I don't know how to do that, be it using XAML only or code behind.
Any help on how to do this would be very much appreciated.

Why my autocompletebox does not display any data?

I have a silverlight autocompletebox, am adding the ItemsSource in the codebehind.cs , also set the valuemember path as well, it does not display any data.
here is the code,
<sdk:AutoCompleteBox Margin="105,2,40,0" ItemsSource="{Binding}" ValueMemberPath="Code" FilterMode="Contains" IsTextCompletionEnabled="True" x:Name="txtcode" Height="23" VerticalAlignment="Top" TabIndex="1" TabNavigation="Local" >
<sdk:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock />
</DataTemplate>
</sdk:AutoCompleteBox.ItemTemplate>
</sdk:AutoCompleteBox>
txtcode.ItemsSource = collection;
Possibly you have missed this one inside the DataTemplate,
<TextBlock Text="{Binding Code}" />
You Should bind that textbox first
Sample Code:
<sdk:AutoCompleteBox Margin="105,2,40,0" ItemsSource="{Binding}" ValueMemberPath="Code" FilterMode="Contains" IsTextCompletionEnabled="True" x:Name="txtcode" Height="23" VerticalAlignment="Top" TabIndex="1" TabNavigation="Local" >
<sdk:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Item}" />
</DataTemplate>
</sdk:AutoCompleteBox.ItemTemplate>
</sdk:AutoCompleteBox>
txtcode.ItemsSource = collection;

display computed property in silverlight

I want to display first & last name of person in my form (xaml)
I use binding for getting person property from screen but I don't have computed property in screen because I don't know how can I create this one!!
In that code I use only firstname but I want first and last name!!! :(
<telerik:Label Grid.Row="4" Grid.Column="0" Content="{Binding PersonelPropertiesTab,Source={StaticResource localResource}}"/>
<telerik:RadComboBox Grid.Row="4" Grid.Column="1" ItemsSource="{Binding Screen.PersonelProperties}"
SelectedItem="{Binding Screen.CurriculuminformationProperty.PersonelProperty,Mode=TwoWay}"
SelectedValue="Id" DisplayMemberPath="applicantfirstname"/>
<viewer:DescriptionViewer Grid.Row="4" Grid.Column="5" Description="{Binding PersonelPropertiesTab,Source={StaticResource localResource}}"/>
I read some article about thatthey are for lightswitch not silverlight.
Could you give me good references?
Instead of setting the DisplayMemberPath, you may set a DataTemplate for the ComboBox items. I haven't tested that with a RadComboBox, but I assume that it behaves like a standard ComboBox:
<telerik:RadComboBox ...>
<telerik:RadComboBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Inlines>
<Run Text="{Binding FirstName}"/>
<Run Text=" "/>
<Run Text="{Binding LastName}"/>
</TextBlock.Inlines>
</TextBlock>
</DataTemplate>
</telerik:RadComboBox.ItemTemplate>
</telerik:RadComboBox>

Resources