绑定TileBrush中的标签?

时间:2013-03-22 13:35:50

标签: wpf xaml binding user-controls visualbrush

我正在使用时间轴控件,到目前为止我有: enter image description here

我需要将'00:00'标记与其实际值绑定。 第一个,如图所示,应该是'00:01',下一个蓝线应该是'00:02'

我知道我的设计可能需要工作,但我需要看看我所处的路径是否正确。我不认为我目前正走在正确的道路上。我不认为在Tile模式下使用VisualBrush是我的时间轴中秒线的正确解决方案。

此时间轴控件的代码分为两个UserControls,我使用TileBush来重绘时间轴。

控制1:

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="WpfApplication1.UserControl1"
x:Name="UserControl" HorizontalAlignment="Center" VerticalAlignment="Top" UseLayoutRounding="True">

<Grid x:Name="LayoutRoot" HorizontalAlignment="Center" Width="431" ClipToBounds="True" SnapsToDevicePixels="False" UseLayoutRounding="True">
    <Grid Height="30" SnapsToDevicePixels="True" Margin="-35,0,0,0">
        <Grid SnapsToDevicePixels="False">
            <Grid.Background>
                <VisualBrush TileMode="Tile" Viewport="0,0,5,30" ViewportUnits="Absolute" Viewbox="0,0,5,30" ViewboxUnits="Absolute">
                    <VisualBrush.Visual>
                        <Line Stroke="Coral" StrokeThickness="2" X1="0" X2="0" Y1="25" Y2="30" UseLayoutRounding="True" />
                    </VisualBrush.Visual>
                </VisualBrush>
            </Grid.Background>
        </Grid>
        <Grid Margin="50,0,0,0" SnapsToDevicePixels="False" UseLayoutRounding="True">
            <Grid.Background>
                <VisualBrush TileMode="Tile" Viewport="0,0,50,30" ViewportUnits="Absolute" Viewbox="0,0,50,30" ViewboxUnits="Absolute">
                    <VisualBrush.Visual>
                        <Line Stroke="Red" StrokeThickness="2" X1="0" X2="0" Y1="20" Y2="30" UseLayoutRounding="True" />
                    </VisualBrush.Visual>
                </VisualBrush>
            </Grid.Background>
        </Grid>

        <Grid SnapsToDevicePixels="False" Height="30" UseLayoutRounding="True" >
            <Grid.Background>
                <VisualBrush TileMode="Tile" Viewport="0,0,500,30" ViewportUnits="Absolute" Viewbox="0,0,500,30" ViewboxUnits="Absolute">
                    <VisualBrush.Visual>
                        <Grid HorizontalAlignment="Left" Width="500" UseLayoutRounding="True">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="21*"/>
                                <ColumnDefinition Width="25*"/>
                                <ColumnDefinition Width="25*"/>
                                <ColumnDefinition Width="25*"/>
                                <ColumnDefinition Width="25*"/>
                                <ColumnDefinition Width="25*"/>
                                <ColumnDefinition Width="25*"/>
                                <ColumnDefinition Width="25*"/>
                                <ColumnDefinition Width="25*"/>
                                <ColumnDefinition Width="20*"/>
                                <ColumnDefinition Width="9*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="15"/>
                                <RowDefinition Height="1*"/>
                            </Grid.RowDefinitions>
                            <Label Grid.Row="0" FontFamily="Tahoma" FontSize="8" Padding="0" VerticalAlignment="Bottom" Grid.Column="1" Height="9" Content=".100" Foreground="White"/>
                            <Label Grid.Row="0" FontFamily="Tahoma" FontSize="8" Padding="0" VerticalAlignment="Bottom" Grid.Column="2" Height="9" Content=".200" Foreground="White"/>
                            <Label Grid.Row="0" FontFamily="Tahoma" FontSize="8" Padding="0" VerticalAlignment="Bottom" Grid.Column="3" Height="9" Content=".300" Foreground="White"/>
                            <Label Grid.Row="0" FontFamily="Tahoma" FontSize="8" Padding="0" VerticalAlignment="Bottom" Grid.Column="4" Height="9" Content=".400" Foreground="White"/>
                            <Label Grid.Row="0" FontFamily="Tahoma" FontSize="8" Padding="0" VerticalAlignment="Bottom" Grid.Column="5" Height="9" Content=".500" Foreground="White"/>
                            <Label Grid.Row="0" FontFamily="Tahoma" FontSize="8" Padding="0" VerticalAlignment="Bottom" Grid.Column="6" Height="9" Content=".600" Foreground="White"/>
                            <Label Grid.Row="0" FontFamily="Tahoma" FontSize="8" Padding="0" VerticalAlignment="Bottom" Grid.Column="7" Height="9" Content=".700" Foreground="White"/>
                            <Label Grid.Row="0" FontFamily="Tahoma" FontSize="8" Padding="0" VerticalAlignment="Bottom" Grid.Column="8" Height="9" Content=".800" Foreground="White"/>
                            <Label Grid.Row="0" FontFamily="Tahoma" FontSize="8" Padding="0" VerticalAlignment="Bottom" Grid.Column="9" Height="9" Content=".900" Foreground="White"/>
                        </Grid>
                    </VisualBrush.Visual>
                </VisualBrush>
            </Grid.Background>
        </Grid>
    </Grid>
</Grid>

控制2:

<UserControl x:Class="WpfApplication1.UserControl2"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:WpfApplication1"
         mc:Ignorable="d" d:DesignHeight="30" d:DesignWidth="1000">

<StackPanel x:Name="stackPanel" Orientation="Horizontal">
    <StackPanel.Background>
        <VisualBrush TileMode="Tile" Viewport="0,0,900,30" ViewportUnits="Absolute" Viewbox="0,0,900,30" ViewboxUnits="Absolute">
            <VisualBrush.Visual>
                <StackPanel Orientation="Horizontal">

                    <local:UserControl1 Width="430" UseLayoutRounding="True" />

                    <Grid VerticalAlignment="Top" Width="20" ClipToBounds="True" UseLayoutRounding="True">

                        <Grid Height="30">
                            <Grid.Background>
                                <VisualBrush TileMode="Tile" Viewport="0,0,5,30" ViewportUnits="Absolute" Viewbox="0,0,5,30" ViewboxUnits="Absolute">
                                    <VisualBrush.Visual>
                                        <Line Stroke="Coral" StrokeThickness="2" X1="0" X2="0" Y1="25" Y2="30" />
                                    </VisualBrush.Visual>
                                </VisualBrush>
                            </Grid.Background>
                        </Grid>

                            <Grid Height="30" Margin="0,0,0,0" SnapsToDevicePixels="False" >
                                <Grid.Background>
                                    <VisualBrush TileMode="Tile" Viewport="0,0,40,30" ViewportUnits="Absolute" Viewbox="0,0,40,30" ViewboxUnits="Absolute">
                                        <VisualBrush.Visual>
                                            <Grid VerticalAlignment="Top">
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="15"/>
                                                    <RowDefinition Height="1*"/>
                                                </Grid.RowDefinitions>
                                                <Label Content="00:00" FontFamily="Tahoma" FontSize="8" Padding="0" VerticalAlignment="Top" Grid.Row="0" Foreground="White" UseLayoutRounding="True"/>
                                            </Grid>
                                        </VisualBrush.Visual>
                                    </VisualBrush>
                                </Grid.Background>
                            </Grid>

                        <Grid Height="30" SnapsToDevicePixels="False" Margin="10,0,0,0" UseLayoutRounding="True" >
                            <Grid SnapsToDevicePixels="True" >
                                <Grid.Background>
                                    <VisualBrush TileMode="Tile" Viewport="0,0,40,30" ViewportUnits="Absolute" Viewbox="0,0,40,30" ViewboxUnits="Absolute">
                                        <VisualBrush.Visual>
                                            <Grid VerticalAlignment="Top">
                                                <Line Stroke="#FF071DFD" StrokeThickness="2" X1="0" X2="0" Y1="15" Y2="30" />
                                            </Grid>
                                        </VisualBrush.Visual>
                                    </VisualBrush>
                                </Grid.Background>
                            </Grid>
                        </Grid>

                    </Grid>

                    <local:UserControl1 Width="430"/>

                    <Grid VerticalAlignment="Top" Width="20" ClipToBounds="True" UseLayoutRounding="True">
                        <Grid Height="30">
                            <Grid.Background>
                                <VisualBrush TileMode="Tile" Viewport="0,0,5,30" ViewportUnits="Absolute" Viewbox="0,0,5,30" ViewboxUnits="Absolute">
                                    <VisualBrush.Visual>
                                        <Line Stroke="Coral" StrokeThickness="2" X1="0" X2="0" Y1="25" Y2="30" />
                                    </VisualBrush.Visual>
                                </VisualBrush>
                            </Grid.Background>
                        </Grid>

                        <Grid Height="30" Margin="0,0,0,0" SnapsToDevicePixels="False" >
                            <Grid SnapsToDevicePixels="True" >
                                <Grid.Background>
                                    <VisualBrush TileMode="Tile" Viewport="0,0,40,30" ViewportUnits="Absolute" Viewbox="0,0,40,30" ViewboxUnits="Absolute">
                                        <VisualBrush.Visual>
                                            <Grid VerticalAlignment="Top">
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="15"/>
                                                    <RowDefinition Height="1*"/>
                                                </Grid.RowDefinitions>
                                                <Label Content="00:00" FontFamily="Tahoma" FontSize="8" Padding="0" VerticalAlignment="Top" Grid.Row="0" Foreground="White" UseLayoutRounding="True" />
                                            </Grid>
                                        </VisualBrush.Visual>
                                    </VisualBrush>
                                </Grid.Background>
                            </Grid>
                        </Grid>

                        <Grid Height="30" SnapsToDevicePixels="False" Margin="10,0,0,0" UseLayoutRounding="True" >
                            <Grid SnapsToDevicePixels="True" >
                                <Grid.Background>
                                    <VisualBrush TileMode="Tile" Viewport="0,0,40,30" ViewportUnits="Absolute" Viewbox="0,0,40,30" ViewboxUnits="Absolute">
                                        <VisualBrush.Visual>
                                            <Grid VerticalAlignment="Top">
                                                <Line Stroke="#FF071DFD" StrokeThickness="2" X1="0" X2="0" Y1="15" Y2="30" />
                                            </Grid>
                                        </VisualBrush.Visual>
                                    </VisualBrush>
                                </Grid.Background>
                            </Grid>
                        </Grid>

                    </Grid>

                </StackPanel>
            </VisualBrush.Visual>
        </VisualBrush>
    </StackPanel.Background>
</StackPanel>

在MainWindow中:

        <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled" >
            <local:UserControl2 Width="3059"  />
        </ScrollViewer>

0 个答案:

没有答案