【问题标题】:Reference point for lines in list view列表视图中线的参考点
【发布时间】:2014-04-07 03:56:49
【问题描述】:

我试图在画布上显示一些线条,这些线条在 Y 轴位置上有所不同,因此创建了一个项目控件并绑定到一个字典,该字典具有 Y 值和一些要在线显示的文本。

我的问题是该线参考单个项目的原点显示到 (x1,y1)(x2,y2) 点,但我希望每条线从画布原点取 Y 轴距离。

<Canvas Margin="0,8,0,8" Height="374" Width="150"  >
<ItemsControl ItemsSource="{Binding Path=YPointsDictionary Margin="0">

<ItemsControl.ItemTemplate>
  <DataTemplate>
             <StackPanel Orientation="Horizontal">
          <Line  X1="0" Y1="{Binding Value}" X2="150" Y2="{Binding Value}" 
              StrokeThickness="2" Stroke="Yellow" StrokeDashArray="2,2"  />
         <Label Content="{Binding Key}" Foreground="Yellow" />                 
      </StackPanel>
    </DataTemplate>
    </ItemsControl.ItemTemplate>
   </ItemsControl>
  </Canvas>

【问题讨论】:

    标签: c# .net wpf xaml


    【解决方案1】:

    使 stackPanel Orientation 垂直给出结果。这是你想要的吗?

    例如:

      <StackPanel Orientation="Vertical"  >
            <Line X1="0" Y1="50" X2="150" Y2="50" Stroke="red" StrokeThickness="5"></Line>
            <Line X1="0" Y1="100" X2="150" Y2="100" Stroke="Blue" StrokeThickness="5"></Line>
            <Line X1="0" Y1="150" X2="150" Y2="150" Stroke="green" StrokeThickness="5"></Line>
        </StackPanel>
    

    【讨论】:

      【解决方案2】:

      我在这里找到了答案。我需要将画布左侧和顶部绑定为每个项目的 X 和 Y 原点。 How to bind a canvas to a list of rectangles

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-11-29
        • 1970-01-01
        • 1970-01-01
        • 2021-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多