CancelButton & InfoBarMessageControl default text

Feb 16, 2012 at 7:35 AM

Hi,

I have maybe a dumb question. Is it possible to change default CancelButton text for purposes of localization without need to create the whole localization profile and recompilation of Catel? Simillary, I would need to change default text of InfoBarMessageControl ("The followinf warnings and/or errors were found (hover to view):"), is tehere any way to do this?

Using 2.5.

Thank you.

Tomas

Feb 16, 2012 at 7:38 AM

Yes, this is possible.

InfoBarMessageControl

Text property, by default loaded from the resources, but you can always set this manually.

 

DataWindow cancel button

You will have to create a custom button using the AddCustomButton method in the constructor of your window. Then, you also have to pass DataWindowMode.Custom to the base constructor. Then you can do whatever you want to do with the buttons.

Feb 16, 2012 at 8:56 PM

Thank you, I am trying hard to do this for a long time, but with no success.What am I doing wrong? I have catel DataWindow and I am trying to set the InfoBarMesageControl text this way:

 <catel:DataWindow.Resources>
        <Style TargetType="catel:InfoBarMessageControl">
            <Setter Property="Text" Value="Test" />
        </Style>
    </catel:DataWindow.Resources>

but it is not working. Am I missing something?

Tomas

Feb 16, 2012 at 9:21 PM

I am not sure how that works. You might want to try to set the value in the code behind. For example, you can use this in the code-behind of the window:

var infoBarMessageControl = this.GetAncestorObject<InfoBarMessageControl>();
infoBarMessageControl.Text = "Test";

Feb 16, 2012 at 9:47 PM

Thank you for your interest and quick answers. This is not working, as TargetInvocationException occurs when trying to set property. I think I have to rewrite and recomplile the whole localization resources pack.

Tomas

Feb 19, 2012 at 9:32 PM

I just tried this and it simply works:

    <catel:InfoBarMessageControl Text="hi there">
        <Grid>
            <catel:WarningAndErrorValidator Source="{Binding}" />

            <catel:StackGrid>
                <catel:StackGrid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </catel:StackGrid.RowDefinitions>

                <catel:StackGrid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </catel:StackGrid.ColumnDefinitions>

                <Label Content="First name" />
                <TextBox Text="{Binding FirstName, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" />

                <Label Content="Middle name" />
                <TextBox Text="{Binding MiddleName, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" />

                <Label Content="Last name" />
                <TextBox Text="{Binding LastName, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" />

                <WrapPanel Grid.ColumnSpan="2" Style="{StaticResource RightAlignedButtonsWrapPanelStyle}">
                    <Button x:Name="saveButton" Content="Save" Style="{StaticResource RightAlignedFixedSizeButtonStyle}" />
                    <Button x:Name="saveAndCloseButton" Content="Save &amp; close" Style="{StaticResource RightAlignedFixedSizeButtonStyle}" />
                    <Button x:Name="cancelButton" Content="Cancel" Style="{StaticResource RightAlignedFixedSizeButtonStyle}" />
                    <Button x:Name="cancelAndCloseButton" Content="Cancel &amp; close" Style="{StaticResource RightAlignedFixedSizeButtonStyle}" />
                    <Button x:Name="closeButton" Content="Close" Style="{StaticResource RightAlignedFixedSizeButtonStyle}" />
                </WrapPanel>
            </catel:StackGrid>
        </Grid>
    </catel:InfoBarMessageControl>

This isn't possible for you?

Feb 19, 2012 at 9:39 PM

And I made a mistake, you shouldn't use the GetAncestory, but Descendent (it's a child, not a parent):

var infoBarMessageControl = this.FindVisualDescendantByType<InfoBarMessageControl>();
infoBarMessageControl.Text = "Test";

Feb 20, 2012 at 6:40 AM

Thank you Geert, this is exactly what I was looking for. Your first solution works, but it is useful only if using the window class, because in DataWindow it displays the second InfoBarMessageControl as the first one is beeing displayed by datawindow. I was trying to do same thing by setting this in resources of dataWindow, but it vasn't working.

The second solution seting the text in code-behind works great and is completelz sufficient for me.

Thanks.

Tomas