Data bindings in Data Template not working

泄露秘密 提交于 2019-12-21 19:55:43

问题


I have UserControl to do filtering for several presentations, which in turn has a ContentControl. The content are the individual filtering controls that vary among the presentations.

The scheme works as intended visually, but the data bindings do not. There are no data binding errors in output. The DataContext is from a view model call PimMasterVm, which otherwise seems correctly wired (ie, the status of 5 avalable people, etc)

Can someone help me trouble shoot this?

Cheers,
Berryl

Filtering Control

<Grid>
    <Border Style="{StaticResource FilterPanelBorderStyle}">
        <StackPanel Orientation="Horizontal" x:Name="myFilterPanel" >
            <ContentControl x:Name="ctrlFilters" 
                            ContentTemplate="{Binding Path=FilterContentKey, Converter={StaticResource filterTemplateContentConv}}" />
            <Button x:Name="btnClearFilter" Style="{StaticResource FilterPanelClearButtonStyle}" />
            <Label x:Name="lblStatus" Style="{StaticResource FilterPanelLabelStyle}" Content="{Binding Status}" />

        </StackPanel>
    </Border>

</Grid>

Data Template (resource)

<DataTemplate x:Key="pimFilterContent">
    <StackPanel Orientation="Horizontal" >
        <cc:SearchTextBox x:Name="stbLastNameFilter" 
            Style="{StaticResource FilterPanelSearchTextBoxStyle}"
            Text="{Binding Path=LastNameFilter, UpdateSourceTrigger=PropertyChanged}" 
                        />
        <cc:SearchTextBox x:Name="stbFirstNameFilter" 
            Style="{StaticResource FilterPanelSearchTextBoxStyle}"
            Text="{Binding Path=FirstNameFilter, UpdateSourceTrigger=PropertyChanged}" 
                        />
    </StackPanel>
</DataTemplate>

回答1:


There is current view model in DataContext of the "ctrlFilters" ContentControl, bind it to Content property:

...

    <ContentControl x:Name="ctrlFilters" 
                    Content="{Binding}"
                    ContentTemplate="{Binding Path=FilterContentKey, Converter={StaticResource filterTemplateContentConv}}" />

...    


来源:https://stackoverflow.com/questions/7499754/data-bindings-in-data-template-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!