我刚刚对其进行了测试,似乎绑定不适用于AppBar.IsOpen
.
我也绑定了一个Button.IsEnabled
到GridView.SelectedItem
,并且按钮被正确设置为false
,但AppBar.IsOpen
不是,转换器只被调用一次按钮绑定。
它可能与此有关:http: //msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.appbar.isopen
注意 绑定到 IsOpen 属性不会产生预期的结果,因为设置属性时不会发生 PropertyChanged 通知。
虽然我认为这只是另一个方向。(编辑:这是一个类似的帖子:open the appbar in metro style apps using binding property)
这是我使用的代码:
<common:LayoutAwarePage.BottomAppBar>
<AppBar IsOpen="{Binding SelectedItem, Converter={StaticResource ObjectToBooleanConverter}, ElementName=gridView}"
IsSticky="True"
Background="#E5F50000" />
</common:LayoutAwarePage.BottomAppBar>
<Grid Style="{StaticResource LayoutRootStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="140" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GridView x:Name="gridView"
HorizontalAlignment="Right"
Margin="0"
Grid.Row="1"
Width="469">
<Button Content="asdf" />
<Button Content="asdf" />
<Button Content="asdf" />
</GridView>
<Button x:Name="bsetnull"
Content="setnull"
HorizontalAlignment="Left"
Margin="78,10,0,0"
Grid.Row="1"
VerticalAlignment="Top" Tapped="bsetnull_Tapped"/>
<Button x:Name="bsettoone"
Content="settoone"
HorizontalAlignment="Left"
Margin="78,71,0,0"
Grid.Row="1"
VerticalAlignment="Top" Tapped="bsettoone_Tapped"/>
<Button Content="Button"
HorizontalAlignment="Left"
Margin="78,147,0,0"
Grid.Row="1"
VerticalAlignment="Top"
IsEnabled="{Binding SelectedItem, Converter={StaticResource ObjectToBooleanConverter}, ElementName=gridView}" />
</Grid>
和转换器
public class ObjectToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value == null)
return false;
else
return true;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}