ProgressBar and OpacityMask
Posted: 25 Aug 2015, 17:52
Hi,
I'm trying to customize a ProgressBar, but I have two use-cases that are a bit complicated to me:
To answer both these use-cases, I've thought my template could be as follow:
The idea is that "PART_Track" represents the empty bar and "FullTrack" represents the bar completely full, both filling the parent Grid. My idea is to use "PART_Indicator" as an OpacityMask, so that I only display the proper proportion of the filled bar.
I can't get it to work on Blend. The bar is completely white, except if the ProgressBar::Value is set to 0 (it becomes fully black). I've tried several combinations but that's the closest I got.
Then, when I use that Template with the XamlPlayer, the application crashes. Here is the content of the file in question (can't upload it directly apparently):
Apparently, it has to do with the OpacityMask, and particularly VisualBrush (I've tried to use a LinearGradientBrush with success elsewhere). Do you see what might go wrong?
Obviously, that would only solve my first use case, but I think I could solve the second use-case with the same kind of operation (using Circle arcs as OpacityMask rather than a simple Rectangle). What do you think?
Thank you,
Alexandre.
Edit:
I confirm there's something about VisualBrush that Noesis does not like. I've made a simpler sample to use them and both my application and the XamlPlay crash when I try using these. That's an important feature to me, what else should I use?
I'm trying to customize a ProgressBar, but I have two use-cases that are a bit complicated to me:
- Segmented bar like that one
- Segmented circular bar
To answer both these use-cases, I've thought my template could be as follow:
Code: Select all
<ControlTemplate>
<Grid>
<Rectangle x:Name="PART_Indicator" Fill="Pink" HorizontalAlignment="Left"/>
<Border x:Name="PART_Track" Background="Black"/>
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="{Binding ElementName=PART_Indicator}"/>
</Grid.OpacityMask>
<Border x:Name="FullTrack" Background="White"/>
</Grid>
</Grid>
</ControlTemplate>I can't get it to work on Blend. The bar is completely white, except if the ProgressBar::Value is set to 0 (it becomes fully black). I've tried several combinations but that's the closest I got.
Then, when I use that Template with the XamlPlayer, the application crashes. Here is the content of the file in question (can't upload it directly apparently):
Code: Select all
<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="Gray" Orientation="Vertical" VerticalAlignment="Center">
<Slider x:Name="PART_Slider" Orientation="Horizontal" Height="22" Maximum="100" Value="4" Width="300"/>
<ProgressBar Height="29.532" Value="{Binding Value, ElementName=PART_Slider}" Width="300">
<ProgressBar.Style>
<Style TargetType="{x:Type ProgressBar}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<Rectangle x:Name="PART_Indicator" Fill="Pink" HorizontalAlignment="Left"/>
<Border x:Name="PART_Track" Background="Black"/>
<Grid>
<Grid.OpacityMask>
<VisualBrush Visual="{Binding ElementName=PART_Indicator}"/>
</Grid.OpacityMask>
<Rectangle Fill="White"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ProgressBar.Style>
</ProgressBar>
</StackPanel>
Obviously, that would only solve my first use case, but I think I could solve the second use-case with the same kind of operation (using Circle arcs as OpacityMask rather than a simple Rectangle). What do you think?
Thank you,
Alexandre.
Edit:
I confirm there's something about VisualBrush that Noesis does not like. I've made a simpler sample to use them and both my application and the XamlPlay crash when I try using these. That's an important feature to me, what else should I use?