我刚测试过它,看起来,绑定不起作用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通知没有预期的结果。
虽然我认为这只意味着另一个方向。 (编辑:这里是一个simialar后:opening 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();
}
}
有一些控制依赖项属性值的优先规则(http://msdn.microsoft.com/zh-cn/library/ms743230.aspx)可能在此处播放。那就是说,你确定你想创造这样的行为吗?这是一个相当主观的,但我认为它可能不是一个用户直观的应用栏有时出现,而不是其他人。也许可以将应用栏上各种命令的启用绑定到选定状态,甚至可以在没有选择的情况下在栏上包含一些文本,以便为用户提供关于如何启用各种功能的提示? –
谢谢尼尔。我有一个项目列表,以及当选择一个项目时变得可见的按钮。我认为将这些按钮放在应用栏中会很明智,然后在选择某个项目时将其打开。事实证明,这很难做到,我一直在寻找XAML中的解决方案。现在,如果我正确地理解了你,你就是说这根本不是一个好主意。保留一组命令的应用栏,并且在选择某个项目时不要更改它。我同意 - 用户会发现这令人困惑。另外,感谢关于依赖属性优先规则的链接。 –