後這裏也有許多搜索的教程我想出了空手而歸,並會很感激的幫助:用戶控件沒有一個窗口內顯示
我有一個包含其他類型的用戶控件的列表的用戶控件。
我想顯示正規WPF窗口內該用戶控件:
這是一個包含用戶控件列表中的用戶控件:
<UserControl x:Class="UsersInfo.InfoLinesContainer"...
...
<Grid>
<ListView ItemsSource="{Binding Path=InfoLineUC_ObservableList,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}">
</ListView>
</Grid>
在我的主窗口,我做的事:
<Window x:Class="UsersInfo.MainAppWindow"
...
xmlns:usrCtr ="clr-namespace:UsersInfo"
...
<usrCtr:InfoLinesContainer Grid.Row="11"
DataContext="{Binding Path=TheInfoLines, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"
ScrollViewer.CanContentScroll="True" Margin="2" Grid.ColumnSpan="7" Grid.RowSpan="6" />
...
TheInfoLines是UserControl的實例,它包含其他UserControl的列表
當我運行該程序窗口出現沒有UserControl裏面它(我得到的是一個空的方形)
我怎樣才能使它工作?
您是否檢查過您的綁定是否正常工作? – meilke