Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Very interesting problem. I myself would like to know more of why the UserControl IsMouseOver changes to false when the TextBlock(s) in its visuals are mouse downed upon.</p> <p>However, here is another way to solve it ... maybe you will like this approach better.</p> <p><strong>Instead of using RadioButton (since you are retemplating it) why don't you just use Control?</strong> (I think IsMouseOver is getting changed to false due to the fact that it is a Button derived control.)</p> <p>Following is the xaml for the Window ...</p> <pre><code>&lt;Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication1" Title="Window1" Width="300" Height="300" &gt; &lt;Window.Resources&gt; &lt;Style TargetType="{x:Type Control}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type Control}"&gt; &lt;local:UserControl1/&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;Border BorderBrush="Black" BorderThickness="2"&gt; &lt;StackPanel&gt; &lt;Control x:Name="OptionButton" Height="100"/&gt; &lt;TextBlock Text="{Binding ElementName=OptionButton, Path=IsMouseOver}"/&gt; &lt;/StackPanel&gt; &lt;/Border&gt; &lt;/Window&gt; </code></pre> <h3>EDIT:</h3> <p>I just wanted to add ... that if you're okay with the above approach ... then, the right thing to do is probably to just use the UserControl in the Window's visual tree versus retemplating a Control. So ... like this:</p> <pre><code>&lt;Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication1" Title="Window1" Width="300" Height="300" &gt; &lt;Border BorderBrush="Black" BorderThickness="2"&gt; &lt;StackPanel&gt; &lt;local:UserControl1 x:Name="OptionButton" Height="100"/&gt; &lt;TextBlock Text="{Binding ElementName=OptionButton, Path=IsMouseOver}"/&gt; &lt;/StackPanel&gt; &lt;/Border&gt; &lt;/Window&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload