Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I bind opacity of specific GridView-Items with a double property of its items-objects Win8.1 App, C#
    primarykey
    data
    text
    <p>I have a scedule with subjects in it. When I turn on a specific mode I want to change the opacity of certain subjects. Therefore I have declared the property:</p> <pre><code> private double _sceduleOpacity; public virtual double SceduleOpacity { get { if (_sceduleOpacity == 0) return 0.9; else return _sceduleOpacity; } set { _sceduleOpacity = value; } } </code></pre> <p>inside the Subject-Object. When the mode is set, the SceduleOpacity-Property of the specific Subject is changed to the desired value (I've checked that).</p> <p>Now all I need is a binding to that Property so that it is visible on the UI. But that is where the problem is. I've tried several approaches:</p> <ol> <li>Bind it to the opacity of the DataTemplate:</li> </ol> <p>GridView:</p> <pre><code>ItemTemplate="{Binding Mode=TwoWay, Source={StaticResource SceduleGridViewTemplate}}" </code></pre> <p>Resourcedictionary:</p> <pre><code>&lt;DataTemplate x:Key="SceduleGridViewTemplate"&gt; &lt;Grid Background="{Binding ColorHash, Converter={StaticResource HexToSolidColorBrushConverter}}" [...] Opacity="{Binding SceduleOpacity}"&gt; &lt;TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center" FontSize="28" Text="{Binding Name}"/&gt; &lt;/Grid&gt; </code></pre> <p>This does not have any effect at all. But since the following binding:</p> <pre><code> &lt;Grid [...]&gt; &lt;TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center" FontSize="28" Text="{Binding Name}" Opacity="{Binding SceduleOpacity}"/&gt; &lt;/Grid&gt; </code></pre> <p>sets the opacity of the displayed text successfully, I went on looking what the problem might be. </p> <ol> <li>Bind it to the opacity of the Style or ItemContainerStyle:</li> </ol> <p>I found out that the opacity of each GridView-Item is set by either in the Styles- or in the ItemContainerStyle-Templates. But still the bindings do not work at all:</p> <p>GridView: Style="{Binding Source={StaticResource SceduleGridViewStyle}, Mode=TwoWay}"></p> <p>Resourcedictionary:</p> <pre><code>&lt;Style x:Key="SceduleItemStyle" TargetType="GridViewItem"&gt; [...] &lt;Setter Property="Opacity" Value="{Binding SceduleOpacity}"/&gt; [...]&lt;/Style&gt; </code></pre> <p>GridView: ItemContainerStyle="{Binding Source={StaticResource SceduleItemStyle}, Mode=TwoWay}"></p> <p>Resourcedictionary:</p> <pre><code>&lt;Style x:Key="SceduleGridViewStyle" TargetType="GridView"&gt; [...] &lt;Setter Property="Opacity" Value="{Binding SceduleOpacity}"/&gt; [...]&lt;/Style&gt; </code></pre> <p>Do you have any idea on how I could fix that? Thank you very much!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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