简体   繁体   English

如何在 Listview 中找到 TextBlock 的值?

[英]How can I find the value of the TextBlock in the Listview?

Some functions change the value of a TextBlock in the ListView .某些函数会更改ListView TextBlock的值。 I want to access TextBlock value at the end of these functions.我想在这些函数的末尾访问TextBlock值。 How can I do it?我该怎么做?

ListView code :列表视图代码:

<ListView BorderThickness="0" x:Name="OrderList">
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel/>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
    <ListView.ItemContainerStyle>
        <Style TargetType="{x:Type ListViewItem}">
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListViewItem}">
                        <Grid Background="{TemplateBinding Background}">
                            <Border BorderBrush="{StaticResource MenuluxRedBrush}" BorderThickness="0,0,0,1" Height="30">
                                <local:OrderPopUpItem/>
                            </Border>
                            <GridViewRowPresenter Grid.RowSpan="2"
                                                  Margin="{TemplateBinding Padding}"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" 
                                        Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

OrderPopUpItem.xaml code : OrderPopUpItem.xaml 代码:

<Grid Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>

        <TextBlock Text="{Binding productName}"
                   VerticalAlignment="Center"
                   Margin="15,0,0,0"
                   FontSize="20"/>

        <Grid Grid.Column="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>

            <Image Source="/Images/PopUp/icon_minus_red.png"
                   MouseLeftButtonUp="azalt"
                   Name="minusIcon"
                   Height="30"/>

            <TextBlock Text="0"
                       Grid.Column="1"
                       Name="amountText"
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center"
                       FontSize="20"/>

            <Image Source="/Images/PopUp/icon_plus_red.png"
                   MouseLeftButtonUp="arttir"
                   Name="plusIcon"
                   Grid.Column="2"
                   Height="30"/>
        </Grid>

If i understand your question correctly, You can achieve this behind code with C#.如果我正确理解你的问题,你可以用 C# 实现这个隐藏的代码。 You should add the code below to your source code.您应该将下面的代码添加到您的源代码中。

//Get ListViewItem    
ListViewItem item = (ListViewItem)OrderList.Items.GetItemAt(SatirIndex);

//Get Content from item (use if you want read items value)
string deger = item.content;
//Set items content (use if you want set items value)
item.content = amountText.Text;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM