1

Some functions change the value of a TextBlock in the ListView. I want to access TextBlock value at the end of these functions. 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 :

<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>
Gh61
  • 9,222
  • 4
  • 28
  • 39
  • 1
    What do you mean by "Some functions change the value of a TextBlock"? Who call those functions? How do they change the value? Are they directly accessing the TextBlock element or ar they setting the value of the productName property, which is bound to the TextBlock Text property? – Iuri Farenzena Sep 04 '20 at 11:57
  • 1
    Use Binding and ItemsSource property, then you access the model not UI elements. Looko into MvvM, will make this a whole lot more less painfull. – XAMlMAX Sep 04 '20 at 12:02
  • Does this answer your question? [WPF TextBlock text Binding](https://stackoverflow.com/questions/14624373/wpf-textblock-text-binding) – Ludovic Sep 04 '20 at 12:07
  • @IuriFarenzena There are two images in OrderItem PopUp.xaml. One increases the count and one decreases it. Finally, he writes to amountText. I want amountText at the end. – Emir Can Aydın Sep 04 '20 at 14:31
  • @Ludovic No, I do not mean that – Emir Can Aydın Sep 04 '20 at 14:31

1 Answers1

0

If i understand your question correctly, You can achieve this behind code with 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;
Schia
  • 232
  • 1
  • 11