您现在的位置: 爱51代码网 >> 范文 >> 文章正文
WPF如何在自己定义的style里动态绑定图片
这是我自己写的一个tabcontrol,然后我已经在里面嵌入了一张图片,我想请教一下各位,能不能写成一个通用的style.直接用在TabItem上面.因为TabItem上不包含图片,不知道怎么做才好
   <TabItem Header="TabItem">
                <TabItem.Style>
                    <Style TargetType="{x:Type TabItem}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type TabItem}">
                                    <ControlTemplate.Resources>
                                        <Storyboard x:Key="Storyboard1">
                                            <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)"
 Storyboard.TargetName="sp">
                                                <EasingColorKeyFrame KeyTime="0" Value="White"/>
                                                <EasingColorKeyFrame KeyTime="0:0:0.2" Value="#FFFFCE4E"/>
                                            </ColorAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </ControlTemplate.Resources>
                                    <StackPanel x:Name="sp" Background="White">
                                        <Image Width="84" Height="70" Source="/Images/TabIcon/3.png" Margin="0,0,0,0" ></Image>
                                        <Label Content="警报管理" HorizontalAlignment="Center"/>
                                    </StackPanel>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Trigger.EnterActions>
                                                <BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>
                                            </Trigger.EnterActions>
                                            <Setter TargetName="sp" Property="Background" Value="#FFFFCE4E"></Setter>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </TabItem.Style>
                <Grid Background="White">
                    <TabControl>
                        <TabItem Header="按日查看">
                            <Grid Background="White" Margin="0,8.163,0,0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="300" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <ListView BorderBrush="Black" x:Name="listView1" BorderThickness="2" ItemsSource="{Binding}" Margin="0,39,0,0" Height="456">
                                    <ListView.View>
                                        <GridView>
                                            <GridViewColumn Header="编号" DisplayMemberBinding="{Binding ID}" Width="80"/>
                                            <GridViewColumn Header="起始时间" DisplayMemberBinding="{Binding BeginTime}" Width="110"/>
                                            <GridViewColumn Header="结束时间" DisplayMemberBinding="{Binding EndTime}" Width="110"/>
                                        </GridView>
                                    </ListView.View>
                                </ListView>
                                <Grid Grid.Column="1" Height="456" Margin="0,39,0,0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="20" />
                                        <RowDefinition Height="1*" />
                                        <RowDefinition Height="1*" />
                                        <RowDefinition Height="1*" />
                                        <RowDefinition Height="1*" />
                                        <RowDefinition Height="20" />
                                    </Grid.RowDefinitions>
                                    <Canvas SnapsToDevicePixels="True" x:Name="canvas1" Width="450" Height="50" Background="Gray"  Grid.Column="1" Grid.Row="1" Panel.ZIndex="1">
                                        <Canvas.ToolTip>
                                            <Label Height="40" Width="100" Background="Gray" Content="关机" FontSize="15" FontWeight="ExtraBold"  Foreground="White"/>
                                        </Canvas.ToolTip>
                                    </Canvas>
                                    <Canvas SnapsToDevicePixels="True" x:Name="canvas2" Width="450" Height="50" Background="Gray"  Grid.Column="1" Grid.Row="2" Panel.ZIndex="1">
                                        <Canvas.ToolTip>
                                            <Label Height="40" Width="100" Background="Gray" Content="关机" FontSize="15" FontWeight="ExtraBold"  Foreground="White"/>
                                        </Canvas.ToolTip>
                                    </Canvas>
                                    <Canvas SnapsToDevicePixels="True" x:Name="canvas3" Width="450" Height="50" Background="Gray"  Grid.Column="1" Grid.Row="3" Panel.ZIndex="1">
                                        <Canvas.ToolTip>
                                            <Label Height="40" Width="100" Background="Gray" Content="关机" FontSize="15" FontWeight="ExtraBold"  Foreground="White"/>
                                        </Canvas.ToolTip>
                                    </Canvas>
                                    <Canvas SnapsToDevicePixels="True" x:Name="canvas4" Width="450" Height="50" Background="Gray"  Grid.Column="1" Grid.Row="4"  Panel.ZIndex="1">
                                        <Canvas.ToolTip>
                                            <Label Height="40" Width="100" Background="Gray" Content="关机" FontSize="15" FontWeight="ExtraBold"  Foreground="White"/>
                                        </Canvas.ToolTip>
                                    </Canvas>
                                </Grid>
                            </Grid>
                        </TabItem>
                        <TabItem Header="按月查看">
 
                        </TabItem>
                    </TabControl>
                </Grid>
            </TabItem>
------------------------------------------------------------------------------------
做一个用户控件 控件添加属性去绑定图片,TabItem的模版就是这个用户空间
  • 上一篇文章:

  • 下一篇文章: 没有了
  • 最新文章 热点文章 相关文章
    maven如何加自定义的包
    redhat 2.6 (santigo 5.6) vsftp
    shell如何实现自动填写操作执行下
    linux shell 文件配置sh:color:
    shell script语法一定要加path吗
    SecureCRT如何访问虚拟机vmWare中
    C#如何读取WINDOWS的放大系数
    cximge的图如何存入数据库并提取
    DBGRID控件显示查询结果文本类型
    TChart控件如何把表中右边的系列
    maven如何加自定义的包
    redhat 2.6 (santigo 5.6) vsftp
    shell如何实现自动填写操作执行下
    linux shell 文件配置sh:color:
    shell script语法一定要加path吗
    SecureCRT如何访问虚拟机vmWare中
    C#如何读取WINDOWS的放大系数
    cximge的图如何存入数据库并提取
    DBGRID控件显示查询结果文本类型
    TChart控件如何把表中右边的系列
    C#字符字串转换成日期出错
    win7x64虚拟机上提示emgu.cv
    .NET Reflector导出"发现不明
    C#如何采集电表数据
    C#两个textBox如何互相控制对
    ExecuteReade如何r创建SqlDa
    如何在ashx页面里面使用Resp
    FormsAuthentication.SetAut
    C#如何读取WINDOWS的放大系数
    C#数据结构和数据类型的区别
     



    设为首页 | 加入收藏 | 网站地图 | 友情链接 |