Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Xaml binding property - count is 0
Message
From
13/09/2011 13:09:01
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Application:
Desktop
Miscellaneous
Thread ID:
01523442
Message ID:
01523444
Views:
35
The multiSelector is a custom control as per below xaml. The interesting part is the binding works in both directions as the values are being initially set to the property in code and visible in the view. If I change it in the view, it updates another control but accessing the property is always a count of 0.

I see there is lots of code in the custom control. Maybe more than I can overcome to fix this right now.
<UserControl x:Class="OCSD.Controls.OCSDMultiSelector"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:OCSD.Controls"
             mc:Ignorable="d" 
             x:Name="MultiSelector">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Themes/OCSDMultiselectorStyleDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
    <Grid VerticalAlignment="Center">
      <Grid.ColumnDefinitions>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
      </Grid.ColumnDefinitions>
      <Label  Grid.Column="0" x:Name="lblText"  VerticalContentAlignment="Center" Content="{Binding LabelText, ElementName=MultiSelector}"></Label>
      <ComboBox Grid.Column="1"
                  Margin="5,5,5,5" Name="cbContainer" DropDownOpened="cbContainer_DropDownOpened" 
                DropDownClosed="cbContainer_DropDownClosed" >
            <ComboBoxItem>
                <TreeView Loaded="tree_Loaded" 
                 CheckBox.Checked="tree_Checked"
                   CheckBox.Unchecked ="tree_Checked"
                      x:Name="tree" 
                      ItemContainerStyle="{StaticResource TreeViewItemStyle}"
                      ItemsSource="{Binding Mode=OneTime}"
                      ItemTemplate="{StaticResource CheckBoxItemTemplate}" 
                      BorderBrush="Transparent"
                    />
            </ComboBoxItem>
        </ComboBox>
    </Grid>
    </StackPanel>
</UserControl>
>Hi,
>Don't know what OCSDMultiSelector is but if the controls SelectedItems is being populated then maybe you need a different UpdateSourceTrigger to update the VM collection ?
>
>>I have a property in a ViewModel class to hold a list of selected items. The binding in xaml works fine in TwoWay mode but if I try to reference the property the count of items is 0 while the binding clearly shows a value greater than 0. What would be the cause of this?
>>
>>binding
>>
>><ctrl:OCSDMultiSelector LabelText ="Route Manager:" x:Name="multiSelectorRouteManager" SelectedItems="{Binding SelectedRouteManagers, Mode=TwoWay}"/>
>>
>>
>>Property in View Model
>>
>>public IList SelectedRouteManagers
>>{
>>     get
>>     {
>>	return _selectedRouteManagers;
>>     }
>>
>>     set
>>     {
>>	if (_selectedRouteManagers != value)
>>	{
>>                           _selectedRouteManagers = value;
>>                          OnPropertyChanged("SelectedRouteManagers");
>>	}
>>     }
>>}
>>private IList _selectedRouteManagers = new WFRouteManagerList();
>>
>>
>>Test shows count at 0 for this property when tested anywhere like below
>>
>>protected override bool CanExecute()
>>{
>>     return View.Scope.Sites.Count > 0
>>	&& ((ViewWorkflow)View).WorkflowContext.SelectedRouteManagers.Count > 0
>>	&& ((ViewWorkflow)View).WorkflowContext.SelectedLOBs.Count > 0;
>>}
>>
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform