如何更改列表框中模板按钮的可见性?
我正在创建 Windows Phone 应用程序,但列表框模板有问题。 我想在运行时隐藏 MoreListBoxStyle 中定义的“MoreButton”。 我尝试创建一个属性并将其绑定到按钮的可见性属性,但它不起作用。
我该怎么办?
<phone:PhoneApplicationPage.Resources>
<Style x:Key="MoreListBoxStyle" TargetType="ListBox">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ScrollViewer x:Name="ScrollViewer" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}">
<StackPanel >
<ItemsPresenter />
<Button x:Name="MoreButton" Content="{Binding Path=LocaleResources.More, Source={StaticResource LocalizedStrings}}" Height="67" Margin="0,0,8,0" BorderBrush="{x:Null}" Foreground="{StaticResource PhoneForegroundBrush}" BorderThickness="0" FontSize="17" FontWeight="Bold" Click="MoreButton_Click" />
</StackPanel>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>
我的列表框是:
<ListBox x:Name="RandomListBox" ItemsSource="{Binding}" Grid.Row="1" Style="{StaticResource MoreListBoxStyle}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding MyText}" TextWrapping="Wrap" Width="440" Margin="0,10" Name="{Binding MyId}" ManipulationCompleted="TextBlock_ManipulationCompleted" />
<TextBlock Text="{Binding Name}" Width="440" TextWrapping="Wrap" TextAlignment="Right" Margin="0,0,0,15" />
<Rectangle Width="440" Height="3" Fill="{StaticResource PhoneForegroundBrush}"></Rectangle>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I am creating a Windows Phone application and I have a problem with a listbox template.
I would like to hide the "MoreButton" defined in the MoreListBoxStyle at runtime.
I tried to create a property and bind it to the visibility property of the button but it doesn't work.
How should I do ?
<phone:PhoneApplicationPage.Resources>
<Style x:Key="MoreListBoxStyle" TargetType="ListBox">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ScrollViewer x:Name="ScrollViewer" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}">
<StackPanel >
<ItemsPresenter />
<Button x:Name="MoreButton" Content="{Binding Path=LocaleResources.More, Source={StaticResource LocalizedStrings}}" Height="67" Margin="0,0,8,0" BorderBrush="{x:Null}" Foreground="{StaticResource PhoneForegroundBrush}" BorderThickness="0" FontSize="17" FontWeight="Bold" Click="MoreButton_Click" />
</StackPanel>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>
And my listbox is :
<ListBox x:Name="RandomListBox" ItemsSource="{Binding}" Grid.Row="1" Style="{StaticResource MoreListBoxStyle}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding MyText}" TextWrapping="Wrap" Width="440" Margin="0,10" Name="{Binding MyId}" ManipulationCompleted="TextBlock_ManipulationCompleted" />
<TextBlock Text="{Binding Name}" Width="440" TextWrapping="Wrap" TextAlignment="Right" Margin="0,0,0,15" />
<Rectangle Width="440" Height="3" Fill="{StaticResource PhoneForegroundBrush}"></Rectangle>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解您的问题,我认为您有两个选择:
如果您使用的是 CLR 属性,请确保您已实现 INotifyPropertyChanged ,例如:
As far as I understand your question I think that you have two options:
If you are using a CLR property than make sure that you have implemented INotifyPropertyChanged like for example: