0

我有一个包含许多列表框的堆栈面板,除了最后一个之外,所有列表框都应该有可见的背景。是否可以从 ControlTemplate 中检测到列表框是最后一个子项并将“Bd”不透明度设置为 0。(MyListBox 扩展列表框)

<Style TargetType="{x:Type local:MyListBox}">
   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type local:MyListBox}">
             <Grid >
             ...
                <Border Grid.Row="0" x:Name="Bd"...>
                   <Border.Background>
                      <ImageBrush Stretch="Fill" ImageSource="/arrayProba1;component/bck/mybck.png" />
                   </Border.Background> 

如果我添加另一个列表框,以前最后一个孩子的旧列表框将获得背景,新的列表框将松散设置“Bd”不透明度 0(稍后将动画)

private List<MyListBox> MyPanels = new List<MyListBox>();

MyPanels.Add(new MyListBox() { Title = "..." });
MyPanelsHolder.Children.Add(MyPanels[n]);

我让它在后面的代码中创建整个样式,但我需要这样做。你会如何处理这个问题?

4

1 回答 1

0

多亏了托尼,我最终是如何做到的……现在是边界

<Border Visibility="{TemplateBinding IsNotCurrent, Converter={StaticResource BoolToVis}}">
  <Border.Background>
    <ImageBrush Stretch="Fill" ImageSource="/arrayProba1;component/Bck/MyBck.png" />

在 MyListBox 类中,我有:

public static readonly DependencyProperty IsNotCurrentProperty =
  DependencyProperty.Register("IsNotCurrent", typeof(bool),
  typeof(MyListBox), new FrameworkPropertyMetadata(false));

public bool IsNotCurrent
{
  get { return (bool)GetValue(IsNotCurrentProperty); }
  set { SetValue(IsNotCurrentProperty, value); }
}

所以每次我添加或删除一个列表框时,我都会设置所有 MyPanels[i].IsNotCurrent = true; 并将最后一个设置为“假”。

稍后我可能会将其全部更改为肯定版本(而不是将 IsNotCurrent 更改为 IsLast)

于 2013-10-09T20:21:47.680 回答