开发者

MVVM Property for datagrid itemssource

I have a datagrid whose itemsSource is bound to a multiconverter which uses a converter.

<toolkit:DataGrid AutoGenerateColu开发者_C百科mns="False">
        <toolkit:DataGrid.ItemsSource>
            <MultiBinding Converter="{StaticResource ProfileConverter}">
                <Binding ElementName="ComboBoxProfiles" Path="SelectedValue" />
                <Binding ElementName="DatePickerTargetDate" Path="SelectedDate" />                   
            </MultiBinding>
        </toolkit:DataGrid.ItemsSource>

This is good because the itemsSource of the grid is updated whenever the combobox or datepicker changes value.

The problem I now have is that in my ViewModel I want to be able to access the ItemSource of my datagrid and either remove items for the list or add new ones.

How do I get access to the itemssource when I have it set up like this?

Many thanks.


How about having three properties in the ViewModel:

public DateTime? SelectedDate
{
    get{return _selectedDate;}
    set
    { 
         _selectedDate = value;
         UpdateItemsSource();
         OnPropertyChanged("SelectedDate");
    }
}
public object SelectedComboBoxValue
{
    get{return _selectedComboBoxValue;}
    set
    { 
         _selectedComboBoxValue= value;
         UpdateItemsSource();
         OnPropertyChanged("SelectedComboBoxValue");
    }
 }
 private void UpdateItemsSource()
 { 
    _itemsSource = //Some fancy expression based on the two fields.
    OnPropertyChanged("ItemsSource");
 }
 public IEnumerable ItemsSource
 {
     get{return _itemsSource;}
 }

Then bind the datepicker, combobox and datagrid to the respective values.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜