1

最初に、xaml コードがあります。

<Grid.Resources>
            <DataTemplate x:Name="dataTemp" x:Key="dtKey">
                <WrapPanel Orientation="Horizontal" Name="mainWP">
                    <TextBlock Name="codeTB" FontSize="18" Width="200" Text="{Binding barcode}"></TextBlock>
(...)
               </WrapPanel>
            </DataTemplate>
        </Grid.Resources>

およびデータテンプレートを使用したリストビュー:

<ListView Name="testLV" Grid.Row="0" ItemTemplate="{StaticResource ResourceKey=dtKey}" >

        </ListView>

したがって、コード ビハインドでは、TextBlock の幅を this.width/5 に変更したいと思います (別の PC では幅が異なる可能性があるため) が、DataTemplate であるため、このコントロールにアクセスできません。Width="{Binding Path=ActualWidth, ElementName=grid0}" も試しましたが、実際の幅として ActualWidth/5 のようなものが必要ですが、うまくいきません

ありがとう

4

2 に答える 2

0

Grid.Columndefination を使用してグリッドをフォーマットするか、そうでなければ Ivaluconverter クラスを使用します 値コンバーターの開発を見てみましょう

変換パラメーターは計算パラメーターになります。値コンバータークラスの作成方法を知っています

 public object Convert(object value, Type targetType, 
        object parameter, CultureInfo culture)
    {
        //value is grid actual width 
       // parameter = 5 is your calculated value

           return value / parameter;
    }
于 2013-07-04T09:30:34.350 に答える