开发者

DataContext does not propagate to children (non-visual) in custom control

开发者 https://www.devze.com 2023-03-21 07:22 出处:网络
<k:GridView Name=\"_masterGridView\" ItemsSource=\"{Binding ProductLocationList}\" SelectedItem=\"{Binding ProductLocationSelected}\">
<k:GridView Name="_masterGridView" 
            ItemsSource="{Binding ProductLocationList}" 
            SelectedItem="{Binding ProductLocationSelected}">
<!-- DataContext does not propagate here automatically in user control... why? -->
    <k:GridView.ExportOptions>
         <k:GridViewExportOptions Title="Production Location Management">
             <k:SearchCriteria >
                 <k:SearchCriterion Title="End Date"
                                    Value="{Binding SearchEndDate}"
                                    ValueFormat="g" />
             </k:SearchCriteria>
         </k:GridViewExportOptions>
    </k:GridView.ExportOptions>
<!-- to here -->

I have to do this hack and it only propagates to GridViewExport option The hack is in the GridView class...

public GridViewExportOptions ExportOptions
{
    get { return _exportOptions; }
    set
    {
        _exportOptions = value;

        if (value != null)
        {
            ExportOptions.SetBinding(FrameworkContentElement.DataContextProperty,
                new Binding("DataContext")
                {
                    Source = this,
                    Mode = BindingMode.T开发者_运维百科woWay
                });
        }
    }
}


You would need to add your GridViewExportOptions as a logical child. Effectively, your GridViewExportOptions would have to derive from FrameworkElement. When your property is changed, you'd have to AddLogicalChild on your GridView (and RemoveLogicalChild to remove the old value, if any). Then you'd have to override LogicalChildren on your GridView and include your option.

You would need to do this in your GridViewExportOptions class as well, with respect to it's "children".

0

精彩评论

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

关注公众号