Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Xaml binding property - count is 0
Message
De
13/09/2011 13:34:12
 
 
À
13/09/2011 13:09:01
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Application:
Desktop
Divers
Thread ID:
01523442
Message ID:
01523446
Vues:
32
Only had time for a quick scan. Do you have the source for the code-behind? Seems to me that maybe what is of interest is what happens when 'tree_Checked' is called - i.e. whether that raises a propertychanged on whatever .SelectedItems is in the user control....
All this only based on the supposition that changes in the selected items in the UI are not propagating back to the VM. From your description is sounds as if that is the problem but I might be reading it wrongly.....

>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;
>>>}
>>>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform