动态缩放DataTemplate中的矩形以反映更改. [英] Scale rectangle in a DataTemplate dynamically to reflect the changes.

查看:69
本文介绍了动态缩放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 ?

推荐答案

THere是执行此操作的几种方法,最简单的方法是使整个datatemplete大小可理解,并将子级值绑定到此父级.

如果那不能解决您的问题,那么我需要更多信息来帮助您:)
THere is a couple of way to do this, the simplest is to make the overall datatemplete size adusteble, and binde the child values to this parent.

If that wont solve your problem then I need more information to help you :)


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆