Note that there are some explanatory texts on larger screens.

plurals
  1. POChange background color on group of objects with ismouseover
    primarykey
    data
    text
    <p>I am really new to WPF+C# and trying to catch up with lots of tutorials at msdn and here at stack. I am currently trying to change the colour of all the objects (at the same time) below (drawing of a house) on <strong>ismouseover</strong> . I can do this with one object (triggers in the code below) at a time but cant figure out some way to change all colours at the same time, here is my xaml code, i have not added anything to xaml.cs I guess that i need to create some for loop but I do not understand how to link the objects drawn in xaml to the code in xaml.cs</p> <pre><code>&lt;Window x:Class="LAB2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="400" Width="600"&gt; &lt;Canvas&gt; &lt;Rectangle Canvas.Left="86" Canvas.Top="190" Height="171" Name="body" Stroke="Black" Width="387"/&gt; &lt;Rectangle Canvas.Left="118" Canvas.Top="229" Height="82" Name="window" Stroke="Black" Width="89"/&gt; &lt;Rectangle Canvas.Left="346" Canvas.Top="229" Height="132" Name="door" Stroke="Black" Width="83"/&gt; &lt;Polygon Points="10,110 230,10 500,110" Fill="Blue" Stroke="Black" Name="triangle" Canvas.Left="35" Canvas.Top="86" /&gt; &lt;Rectangle Canvas.Left="156" Canvas.Top="109" Height="61" Name="chimney" Stroke="Black" Width="36"&gt; &lt;Rectangle.Style&gt; &lt;Style TargetType="{x:Type Rectangle}"&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsMouseOver" Value="True"&gt; &lt;Setter Property="Fill" Value="Red" /&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsMouseOver" Value="False"&gt; &lt;Setter Property="Fill" Value="Blue" /&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/Rectangle.Style&gt; &lt;/Rectangle&gt; &lt;/Canvas&gt; &lt;Window.Resources&gt; &lt;/Window.Resources&gt; </code></pre> <p></p>
    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.
 

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