Need to style the Popup of the errors - PropertyStatus - Silverlight CSLA 4.01

Need to style the Popup of the errors - PropertyStatus - Silverlight CSLA 4.01

Old forum URL: forums.lhotka.net/forums/t/10038.aspx


JJLoubser posted on Monday, February 07, 2011

the Popup of the errors after mouse enter the error indication of CSLA PropertyStatus is not vissible much in our project, it need to be style

- the problem to style it is that you can only style the Popup with code-behind and the code-behind happens in the PropertyStatus.cs class of CSLA

- I was trying to style a popup control like this:

 <Style TargetType="cslaXaml:PropertyStatus"
         >
        <Setter Property="Background" Value="{StaticResource BorderInline1}" />
        <Setter Property="Foreground" Value="Red" />
    </Style>


 <Style TargetType="Popup"
         >
        <Setter Property="Background" Value="{StaticResource BorderInline1}" />
        <Setter Property="Foreground" Value="Red" />
    </Style>

. The cslaXaml:PropertyStatus, but not the Style TargetType="Popup", but I do not think there is a popup control in the xaml

- or we must update that PropertyStatus.cs or find another way?

- any suggestions?

RockfordLhotka replied on Monday, February 07, 2011

I'm not real good at styling stuff with XAML, but you should be able to restyle pretty much all aspects of PropertyStatus. I typically copy the entire style block for the control from the default style in the Csla.Xaml project into my app.xaml and tweak it from there.

Alternately, in 4.1 and higher you can use the PropertyInfo control. It has no visual components at all, allowing you to bind arbitrary UI elements to the properties and events of the control. Of course this means effectively starting from nothing and building up visuals, but it also offers almost limitless flexibility.

JJLoubser replied on Tuesday, February 08, 2011

I was looking for the 'style block for the control', i find it in

C:\Program Files\Marimer LLC\CSLA .NET\4.1.0\Source\CslaSource\Source\Csla.Xaml\Themes\Generic.xaml

thanks

a>)

i copied it in my theme and played with it , it gived error 'Element is already the child of another element' -

on the net is says:

"

Usually this error occurs when the said Element is already attached to an existing Parent and somewhere in your code you're attempting to re-parent it (ie via just straight "add" when you in turn must remove the child from the parent first, then Add it to the children etc)."

and

b.)

just something new: the BooleanAnimationUsingKeyFrames from System.Window.Media.Animation for Siliverlight do not exist so I had to comment it out:

- I tried to make the popup isopen = false but not helping, what else can be wrong?

 

- I also remove the names of some of the elements,

 

MyStyle for my project:

<DataTemplate x:Key="EcoBookingsBrokenRuleTemplate">
        <Grid>
            <Grid.Resources>
                <cslaXaml:BrokenRuleSeverityConverter x:Key="severityConverter" />
            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Image Source="{Binding Severity, Converter={StaticResource severityConverter}}" Width="16" Height="16" Opacity="1" />
            <StackPanel  Grid.Column="1">
                <Border Background="{StaticResource BorderInline1}">
                    <TextBlock Margin="5,2,2,2" Text="{Binding Description}"/>
                </Border>
            </StackPanel>
        </Grid>
    </DataTemplate>

    <Style TargetType="cslaXaml:PropertyStatus">
        <Setter Property="Width" Value="16" />
        <Setter Property="Height" Value="16" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="Gray" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="cslaXaml:PropertyStatus">
                    <Grid  Background="{TemplateBinding Background}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup >
                                <VisualState  >
                                    <Storyboard/>
                                </VisualState>
                                <VisualState  >
                                    <Storyboard >
                                        <!--<mAnimation:ColorAnimationUsingKeyFrames-->
                                        <!--<BooleanAnimationUsingKeyFrames
                                            Storyboard.TargetName="My_busy"
                                            Storyboard.TargetProperty="IsRunning"
                                            BeginTime="00:00:00">
                                            <DiscreteBooleanKeyFrame KeyTime="0" Value="False" />
                                        </BooleanAnimationUsingKeyFrames>-->
                                        <DoubleAnimation
                                            Storyboard.TargetName="My_errorImage"
                                            Storyboard.TargetProperty="Opacity"
                                            BeginTime="00:00:00"
                                            Duration="0.00:00:01"
                                            From="0"
                                            To="1" />
                                        <ObjectAnimationUsingKeyFrames
                                            Storyboard.TargetName="My_errorImage"
                                            Storyboard.TargetProperty="Visibility"
                                            Duration="0">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="My_Warning" >
                                    <Storyboard >
                                        <!--<BooleanAnimationUsingKeyFrames
                                            Storyboard.TargetName="My_busy"
                                            Storyboard.TargetProperty="IsRunning"
                                            BeginTime="00:00:00">
                                            <DiscreteBooleanKeyFrame KeyTime="0" Value="False" />
                                        </BooleanAnimationUsingKeyFrames>-->
                                        <DoubleAnimation
                                                Storyboard.TargetName="My_warningImage"
                                                Storyboard.TargetProperty="Opacity"
                                                BeginTime="00:00:00" Duration="0:0:1"
                                                To="1"/>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="My_warningImage"
                                                                       Storyboard.TargetProperty="Visibility"
                                                                       Duration="0">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="My_Information" >
                                    <Storyboard >
                                        <!--<BooleanAnimationUsingKeyFrames
                                            Storyboard.TargetName="My_busy"
                                            Storyboard.TargetProperty="IsRunning"
                                            BeginTime="00:00:00">
                                            <DiscreteBooleanKeyFrame KeyTime="0" Value="False" />
                                        </BooleanAnimationUsingKeyFrames>-->
                                        <DoubleAnimation
                                                Storyboard.TargetName="My_informationImage"
                                                Storyboard.TargetProperty="Opacity"
                                                BeginTime="00:00:00" Duration="0:0:1"
                                                To="1"/>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="My_informationImage"
                                                                       Storyboard.TargetProperty="Visibility"
                                                                       Duration="0">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="My_MyBusy">
                                    <Storyboard>
                                        <!--<BooleanAnimationUsingKeyFrames
                                                Storyboard.TargetName="My_busy"
                                                Storyboard.TargetProperty="IsRunning"
                                                BeginTime="00:00:00">
                                            <DiscreteBooleanKeyFrame KeyTime="0" Value="True" />
                                        </BooleanAnimationUsingKeyFrames>-->
                                    </Storyboard>
                                </VisualState>
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0:0:0"/>
                                </VisualStateGroup.Transitions>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <!--<cslaXaml:BusyAnimation
                            x:Name="My_busy"
                            Width="{TemplateBinding Width}"
                            Height="{TemplateBinding Height}"
                            IsTabStop="False"/>-->
                        <Image x:Name="My_errorImage"
                               Opacity="0"
                               Visibility="Collapsed"
                               Source="/Csla.Xaml;component/Resources/Error.png"
                               Width="{TemplateBinding Width}"
                               Height="{TemplateBinding Height}" />
                        <Image x:Name="My_warningImage"
                               Opacity="0"
                               Visibility="Collapsed"
                               Source="/Csla.Xaml;component/Resources/Warning.png"
                               Width="{TemplateBinding Width}"
                               Height="{TemplateBinding Height}" />
                        <Image x:Name="My_informationImage"
                               Opacity="0"
                               Visibility="Collapsed"
                               Source="/Csla.Xaml;component/Resources/Information.png"
                               Width="{TemplateBinding Width}"
                               Height="{TemplateBinding Height}" />
                        <Popup >
                            <!-- The child of popup must be of Type ItemsControl -->
                            <!-- {TemplateBinding BrokenRules} does not work (SL bug?) so we have to set
                                 the DataContext in the codebehind, which will trigger the Binding
                            -->
                           
                                    <ListBox
                                        ItemsSource="{Binding}"
                                        ItemTemplate="{StaticResource EcoBookingsBrokenRuleTemplate}"
                                        BorderThickness="1"
                                        IsTabStop="False"/>
                               
                        </Popup>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

 

 

what is missing?

 

justncase80 replied on Tuesday, February 08, 2011

When this control was originally made it was made for Silverlight 2.0 and there were some bad bugs in the runtime with the popups. So in the actual PropertyStatus control code there are some workarounds, which may be unnecessary now.

If you look here:

http://www.lhotka.net/cslacvs/viewvc.cgi/core/trunk/Source/Csla.Xaml/PropertyStatus.cs?view=markup

 

In the PropertyStatus control in the image_MouseEnter method and a few below it you will see that the Popup object is explicitly referenced and has some special code. It may be that most of this is obsolete now in Silverlight, it would be worth looking at Rocky. If you delete the "#if SILVERLIGHT...#endif" block does it still work?

But without more error information I'll try to give you a few direct answers to your questions:

a.) Yes that's right. It's not clear from your description or looking at the code in the repo what is getting re-parented but your description sounds accurate.

b.) you're using the wrong Style and Template for the Silverlight property status you need the one in Csla.Xaml.Silverlight project. Copy that one and play with it and see if that gets you further.

http://www.lhotka.net/cslacvs/viewvc.cgi/core/trunk/Source/Csla.Xaml.Silverlight/themes/Generic.xaml?view=markup

Also I wouldn't remove the names. The controls are named specifically and referenced in the code behind of the control to do certain logic.

JJLoubser replied on Tuesday, February 08, 2011

jip copy the wrong style lol ha ha ha ha

sorry dude cannot party with ya, have to work, but anyway thanks, sea

thanks rocky two

Copyright (c) Marimer LLC