本文介绍了动态缩放DataTemplate中的矩形以反映更改.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataTemplate

I have a DataTemplate

<Window.Resources>
         <DataTemplate x:Key="BarChartItemsTemplate">
         <Border Width="385" Height="50">
            <Grid>
               <Rectangle Name="rectangleBarChart" Fill="MediumOrchid" StrokeThickness="2" Height="40" Width="{Binding}" HorizontalAlignment="Right" VerticalAlignment="Bottom">
                  <Rectangle.LayoutTransform>
                     <ScaleTransform ScaleX="4"/>
                  </Rectangle.LayoutTransform>
               </Rectangle>
               <TextBlock Margin="14" FontWeight="Bold" HorizontalAlignment="Right" VerticalAlignment="Center" Text="{Binding}">
                  <TextBlock.LayoutTransform>
                     <TransformGroup>
                        <RotateTransform Angle="90"/>
                        <ScaleTransform ScaleX="-1" ScaleY="1"/>
                     </TransformGroup>
                  </TextBlock.LayoutTransform>
               </TextBlock>
            </Grid>
         </Border>
      </DataTemplate>
  </Window.Resources>




我已将数据模板用于ListBox,如下所示:




I have used the datatemplate for a ListBox as follows:

<ListBox Name="barChartListBox" ItemsSource="{Binding}" BorderThickness="0" ItemTemplate="{DynamicResource BarChartItemsTemplate}" ItemsPanel="{DynamicResource BarChartItemsPanel}" Margin="36,-3,48,12"></ListBox>



我可以使用VisualTreeHelper
找到rectangleBarChart我在后面的代码中更改了矩形属性,但是更新后的值未更新.

任何提示吗?



I am able to find the rectangleBarChart using the VisualTreeHelper
I am changing the rectangle properties in the code-behind, but the updated values are not updated.

Any Hints ?

推荐答案


这篇关于动态缩放DataTemplate中的矩形以反映更改.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 06:51