0

我想要ListBox代码中的控件。以下我写的代码:

<ListBox x:Name="listbox" Grid.Column="0" SelectedIndex="0" BorderThickness="0" Style="{StaticResource myListboxStyle}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Hidden" ItemsSource="{Binding IsAsync=True}" DataContext="{Binding IsAsync=True}" ItemStringFormat="{Binding IsAsync=True}" BorderBrush="Black" IsEnabled="True">

<ListBox.ItemTemplate> 
    <DataTemplate>
        <Grid x:Name="gridEmployee" Height="90" Margin="1,0,0,1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="80" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="25" />
            </Grid.ColumnDefinitions>

        <Grid x:Name="pic" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="8,8,0,8">
            <Border Name="mask" CornerRadius="7" removed="White" />

            <Image x:Name="imgEmp" Height="50" Width="50" Stretch="Fill">
                <Image.OpacityMask>
                    <VisualBrush Visual="{Binding ElementName=mask}"/>
                </Image.OpacityMask>

                <Image.Style>
                    <Style TargetType="{x:Type Image}">
                        <Setter Property="Source" Value="{Binding Path=PicPhoto, IsAsync=True}"></Setter>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=PicPhoto, IsAsync=True}" Value="{x:Null}">
                                <Setter Property="Source" Value="/TimeAttendance_PageTransition;component/Images/blank.jpg" />
                            </DataTrigger>
                        </Style.Triggers> 
                    </Style>
                </Image.Style>
            </Image>
        </Grid>

        <StackPanel Name="spEmpData" Margin="5,6,0,0" Width="206" Grid.Column="1">
            <TextBlock Name="tbEmpName" TextBlock.FontWeight="Bold" Text="{Binding Path=Staff_Name_e, IsAsync=True}" Margin="0,6,0,0" FontSize="22" FontFamily="Browallia New">
                <TextBlock.Effect>
                    <DropShadowEffect Color="White" BlurRadius="2" Direction="280" ShadowDepth="2"/>
                </TextBlock.Effect>
            </TextBlock>

            <TextBlock Name="tbPunchDate" Text="{Binding Path=Punch_Date, IsAsync=True}" Margin="0,0,0,0" FontSize="13" Foreground="#FF545454">

                <TextBlock.Effect>
                    <DropShadowEffect Color="White" BlurRadius="2" Direction="280" ShadowDepth="2"/>
                </TextBlock.Effect>
            </TextBlock>

            <TextBlock Name="tbEmpCode" Text="{Binding Path=Emp_Code, IsAsync=True}" Margin="0,3,0,0" FontSize="13" Foreground="#FF545454">

                <TextBlock.Effect>
                    <DropShadowEffect Color="White" BlurRadius="2" Direction="280" ShadowDepth="2"/>
                </TextBlock.Effect>
            </TextBlock>
    </StackPanel>

    <Canvas Grid.Column="2">
        <Ellipse Margin="0,11,0,0" Height="18" Width="18" Opacity="1" VerticalAlignment="Top" HorizontalAlignment="Center" d:LayoutOverrides="Width">
            <Ellipse.Fill>
                <LinearGradientBrush EndPoint="0.0,0.1" StartPoint="0.0,0.0">
                    <GradientStop Color="{Binding Path=Function_Key, IsAsync=True}" Offset="1"/>
                </LinearGradientBrush>
            </Ellipse.Fill>
        </Ellipse>    
    </Canvas>   
</Grid>

    <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True">
                <Setter TargetName="tbEmpName" Property="Foreground" Value="Black"/>
                <Setter TargetName="tbEmpCode" Property="Foreground" Value="Black"/>
                <Setter TargetName="tbPunchDate" Property="Foreground" Value="Black"/>
                <Setter TargetName="gridEmployee" Property="Background">

                <Setter.Value>
                    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                        <GradientStop Color="{DynamicResource {x:Static SystemColors.GradientActiveCaptionColorKey}}" Offset="0"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
        </DataTrigger>
    </DataTemplate.Triggers>
    </DataTemplate>
</ListBox.ItemTemplate>

    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>

这是我的ListBox,我想要ListBox代码后面的内部控件来更改列表框项的内容。我在后面的代码中获得ListBox了控制权('listbox'),但我没有在后面的代码中获得Image('imgEmp')和文本块。

显然,我想控制列表框项目,如 VB 6 中的 Control 数组。我应该如何实现这一点?

提前致谢。

4

1 回答 1

0

您可以使用 VisualTreeHelper 类来迭代视觉效果请参阅 链接

于 2013-06-06T06:59:12.850 回答