Help on Datawrapper<>

Aug 15, 2010 at 7:54 AM

I have this in my View Model

 

 

static PropertyChangedEventArgs currentLedgerChangedArgs = ObservableHelper.CreateArgs<LedgerViewModel>(x => x.CurrentLedger);
        Ledger cLedger;
        public Ledger CurrentLedger
        {
            get
            {
                return cLedger;
            }
            set            
            {
                
                cLedger = value;                
                NotifyPropertyChanged(currentLedgerChangedArgs);
            }

        }

 

and my Ledger Class have this

 

 

static PropertyChangedEventArgs parentChangeArgs= ObservableHelper.CreateArgs<Ledger>(x=>x.Parent);
        public DataWrapper<Group> Parent
        {
            get
            {
                return parent;
            }
            set
            {
                parent = value;
                NotifyPropertyChanged(parentChangeArgs);
            }
        }

 

in my View I Bind a combobox selected item to this Parent property of CurrentLedger

 

<ComboBox ItemsSource="{Binding Path=Groups}" SelectedItem="{Binding Path=CurrentLedger.Parent.DataValue,Mode=TwoWay}" 
Grid.Column
="1" Grid.Row="3" Width="250" HorizontalAlignment="Left"> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=Name.DataValue}"/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox>

but when ever i assign CurrentLedger through another List Box

<ListBox Grid.Row="1" ItemsSource="{Binding Path=Group.Ledgers,Mode=TwoWay}" SelectedItem="{Binding Path=CurrentLedger,Mode=TwoWay}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Name.DataValue}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
The combobox is not showing CurrentLedger.Parent.Datavalue as selected. where as i have a textbox and it is set to CurrentLedger.Name.DataValue and it works fine. can you help me out with this problem ?

Aug 15, 2010 at 9:47 AM
I do not know what your problem is here, but I can say I only really meant DataWrapper to wrap a simple type such as Int/string etc etc, anywhere you would put a textbox basically. Sounds like you probably don't want to use DataWrapper<T> for the scenario you describe, I would stick to use primitives. So I would refactor is so your Ledger class used standard Group property, and inside the Group class use DataWrapper, and then you could use standard stuff like ICollectionView and IsSynchronizedWithCurrentItem over your Groups property.
Aug 15, 2010 at 1:14 PM

Thanks for the advice, i will try that.

Aug 15, 2010 at 8:33 PM

I still don't know what the actual problem is, i changed my XAML to look like this. and it worked. ( changed parent property to int. and,

<ComboBox ItemsSource="{Binding Path=Groups}" DisplayMemberPath="Name.DataValue" SelectedValuePath="Id.DataValue" SelectedValue="{Binding Path=CurrentLedger.Parent,Mode=TwoWay}" Grid.Column="1" Grid.Row="3" Width="250" HorizontalAlignment="Left" IsEditable="True" StaysOpenOnEdit="True" />

Aug 16, 2010 at 7:21 AM

Yeah I dont know either, seems quite specific to your app to be honest. Still at least you have it working now.