D
D
Denis2014-07-14 11:47:27
Microsoft Silverlight
Denis, 2014-07-14 11:47:27

How to change the parent control property?

Hello.
There is a simple window (see the code below), with two RadioButtons, since the text in them is formed dynamically, I use a TextBlock. And since the text can be of arbitrary length, then I added ScrollViewer and it turned out not bad, but one problem got out. When you click on the TextBlock, the RadioButton button is not selected, you have to click on the button itself, which is not convenient. If you remove the ScrollViewer, then everything works fine.
There are a couple of questions:
1) What am I missing and how can I fix this problem?
2) I tried to drop in the direction of using triggers, if for example we do Click on a TextBlock or TextBlock.IsFocused = true, set RadioButton.IsChecked = true, but I could not figure out how to do it.
How to change the property of the parent control, based on the property or event of the child control?

<Window x:Class="ChooseView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        mc:Ignorable="d" 
             d:DesignHeight="210" d:DesignWidth="436" MaxHeight="210" MaxWidth="436" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
    <Border Padding="5" BorderBrush="Gray" BorderThickness="2">        
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>                
            </Grid.RowDefinitions>
            <TextBlock Text="Выберите пункт назначения" TextWrapping="Wrap" Margin="5"/>
            <StackPanel Grid.Row="1" Margin="5 10 5 5">                                
                <RadioButton Margin="0 0 0 10" MaxHeight="36" IsChecked="{Binding IsFirst}">
                    <ScrollViewer VerticalScrollBarVisibility="Auto">
                        <TextBlock TextWrapping="Wrap" Text="{Binding FirstInformation}"/>
                    </ScrollViewer>
                </RadioButton>                
                <RadioButton Margin="0 0 0 0" MaxHeight="36" IsChecked="{Binding IsSecond}">
                    <TextBlock TextWrapping="Wrap" Text="{Binding SecondInformation}"/>
                </RadioButton>
            </StackPanel>
            <Button Grid.Row="2" Command="{Binding OkCommand}" Content="ОК" HorizontalAlignment="Center" Width="100" Margin="5"/>
        </Grid>
    </Border>
</Window>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sumor, 2014-07-14
@den_labs

Set the scroll's IsHitTestVisible property to false. Then it will pass events from the mouse through itself and the radiobutton switches normally.

<ScrollViewer VerticalScrollBarVisibility="Auto" IsHitTestVisible="False" >
       <TextBlock TextWrapping="Wrap" Text="{Binding FirstInformation}"/>
</ScrollViewer>

If there is a desire to mess around with events, then you can offer this option (but I would not do that).
<ScrollViewer VerticalScrollBarVisibility="Auto" >
       <TextBlock TextWrapping="Wrap" Text="{Binding FirstInformation}"  MouseLeftButtonUp="TextBlock_MouseLeftButtonUp"/>
</ScrollViewer>

private void TextBlock_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
            var tb = sender as TextBlock;
            // Нужно дополнительно обложиться проверками, что типы совпадают
            ((tb.Parent as ScrollViewer).Parent as RadioButton).IsChecked = true;            
}

D
Denis, 2014-07-16
@den_labs

Thanks for the help, I knew there had to be an easier way.
But, in this case, then scrolling does not work. Is there another property that needs to be configured?

<ScrollViewer VerticalScrollBarVisibility="Auto" IsHitTestVisible="False" >
       <TextBlock TextWrapping="Wrap" Text="{Binding FirstInformation}"/>
</ScrollViewer>

But the second option works with a bang (even triggers are not needed), although I also want to set everything up at the xaml level, but something still fails).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question