0
我有一個主視圖。它包括FirstSubView和SecondSubView。如果主視圖包含子視圖,則將ViewModel屬性綁定到主視圖或子視圖?
<navigation:Page x:Class="Test.Views.PreimaryView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:localViews="clr-namespace:Test.Views"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="1057" d:DesignHeight="707"
Title="TestView Page">
<UserControl.Resources>
<silverlightLib:BooleanVisibilityConverter x:Key="BooleanVisibilityConverter"></silverlightLib:BooleanVisibilityConverter>
</UserControl.Resources>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Background="Transparent">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical">
<localViews:FirstSubView DataContext="{Binding VmFirst, Mode=TwoWay}"></localViews:FirstSubView>
<localViews:SecondSubView DataContext="{Binding VmSecond, Mode=TwoWay}" Visibility="{Binding IsAdjustVisible, Converter={StaticResource BooleanVisibilityConverter}}"></localViews:SecondSubView>
</StackPanel>
</StackPanel>
</ScrollViewer>
你看到SecondSubView我有一個綁定屬性IsAdjustVisible
。
我的問題是我設置它的地方?我在兩個ViewModels中設置它來調整第二個視圖的可見性。但它不起作用,即使它是假的,視圖仍然顯示。
嘗試像這樣。 ' Grid.DataContext> localViews:SecondSubView> –
AVK
@AVKNaidu,有一個類似的[問題](http://stackoverflow.com/questions/4893904/adjust-the-visibility-property-of-a-view-not-working)。我試過了,但它不起作用。 – Bigeyes