This is a migrated thread and some comments may be shown as answers.

RadWindow.Confirm setting default button

10 Answers 361 Views
Window
This is a migrated thread and some comments may be shown as answers.
Dean
Top achievements
Rank 1
Dean asked on 24 Jan 2014, 09:45 PM
By default RadWindow.Confirm defaults to OK button, how would I set the Cancel button to be the default?

10 Answers, 1 is accepted

Sort by
0
Accepted
Kalin
Telerik team
answered on 27 Jan 2014, 12:42 PM
Hello Dean,

In order to have the Cancel as the default button you would need to extract the default ControlTemplate of RadComfirm and modify it. You will need to find the StackPanel which holds the buttons and change its
FocusManager.FocusedElement property to be bound to the Cancel button. I have prepared and attached a sample project which demonstrates the exact approach (note that I have used Implicit Styles to style the controls).

Hope this helps.

Regards,
Kalin
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Dean
Top achievements
Rank 1
answered on 27 Jan 2014, 08:26 PM
That worked, thanks... Here is the style XAML only:

  <Style x:Key="ConfirmStyleCancel" TargetType="t:RadConfirm" BasedOn="{StaticResource RadConfirmStyle}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="t:RadConfirm">
          <Grid x:Name="LayoutRoot">
            <Grid.RowDefinitions>
              <RowDefinition Height="*"/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="Auto"/>
              <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <ContentPresenter x:Name="Icon" VerticalAlignment="Top" Margin="16 8 8 8" 
              ContentTemplate="{StaticResource ConfirmIconTemplate}"/>
            <ScrollViewer IsTabStop="False" Grid.Row="0" Grid.Column="1" HorizontalScrollBarVisibility="Auto" 
              VerticalScrollBarVisibility="Auto" Margin="0 0 0 8">
              <ContentPresenter x:Name="ConfirmText" Margin="8 8 8 0"/>
            </ScrollViewer>
            <Border x:Name="HorizontalRule" Grid.Row="1" Grid.ColumnSpan="2" Grid.Column="0" BorderThickness="0 0 0 1"
              Height="2" VerticalAlignment="Top" Background="{StaticResource BorderLineOuterColor}" 
              BorderBrush="{StaticResource BorderLineInnerColor}"/>
            <StackPanel x:Name="DialogButtons" Grid.Row="1" Grid.ColumnSpan="2" Grid.Column="0" Orientation="Horizontal" 
              HorizontalAlignment="Right" FocusManager.FocusedElement="{Binding ElementName=Cancel}">
              <t:RadButton x:Name="OK" Command="{x:Static t:WindowCommands.Confirm}"
                t:RadWindow.ResponseButton="Accept" MinWidth="70" TabIndex="0" IsTabStop="True" HorizontalAlignment="Right"
                t:LocalizationManager.ResourceKey="Ok" Margin="0 10 8 8"/>
              <t:RadButton x:Name="Cancel" Command="{x:Static t:WindowCommands.Cancel}"
                t:RadWindow.ResponseButton="Cancel" MinWidth="70" TabIndex="1" IsTabStop="True" HorizontalAlignment="Right"
                t:LocalizationManager.ResourceKey="Cancel" Margin="0 10 8 8"/>
            </StackPanel>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

If you need to set it in code behind here is how:

ContentStyle = new Style(typeof(RadConfirm), (Style)FindResource("ConfirmStyleCancel"))
0
Dean
Top achievements
Rank 1
answered on 26 Mar 2014, 08:43 PM
After updating to 2014.1.224 I now get "Cannot find resource named 'ConfirmIconTemplate'."

If I extract that DataTemplate from the style and place it locally with modified RadConfirmStyle it works but it is themed according to the theme xaml I extract if from so it's no longer dynamic and when I change the theme at runtime that RadWindow is no longer dynamically themed.

If I change the style to use DynamicResource instead it can't find it at runtime and doesn't display the icon or the contents correctly.

How do I fix this problem now?
0
Dean
Top achievements
Rank 1
answered on 26 Mar 2014, 09:22 PM
Actually, I did some more digging and it turns out the problem is with the 'Windows7' theme only because it is the only theme that doesn't contain ''ConfirmIconTemplate' DataTemplate at all.
0
Dean
Top achievements
Rank 1
answered on 26 Mar 2014, 09:42 PM
I ended up extracting the RadConfirmStyle of 'Windows7' theme as well and changing its FocusManager.FocusedElement to Cancel. So now I have two modified RadConfirmStyle styles, one for 'Windows7' theme and one for all other themes so in my code I have to do this ugly check within RadWindow.Confirm DialogParameters:

                        ContentStyle = defaultToCancel && ColorScheme != "Windows7" ? 
                            new Style(typeof(RadConfirm), (Style)FindResource("ConfirmStyleCancel")):
                            defaultToCancel && mvm.ColorScheme == "Windows7" ?
                            new Style(typeof(RadConfirm), (Style)FindResource("ConfirmStyleCancelWin7")) :
                            new Style(typeof(RadConfirm), (Style)FindResource("RadConfirmStyle")),

It works but I'm sure you'll agree that is not a good solution so either you need to make sure all your themes are compatible or give us a way to change the default dialog button more easily with a property (that would be and ideal solution).
0
Kalin
Telerik team
answered on 27 Mar 2014, 12:26 PM
Hi Dean,

Thanks for your feedback, we will consider the suggestions for the themes. However instead of using two Styles you can create an additional ResourceDictionary and put inside the missing StaticResource in the Windows7 theme. This way when changing the theme you will need to merge the additional dictionary in order to have the required resource present, so you will be able to use the same Style without a problem. I have prepared a sample project which demonstrates the exact approach. As for the new property suggestion you can log that in our Feedback portal and depending on the user demand it might be considered for implementing.

Hope this work for you.

Regards,
Kalin
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
Dean
Top achievements
Rank 1
answered on 27 Mar 2014, 06:04 PM
Thanks but that's all a hack, please provide a property we can use to set the default button... I mean if a user is deleting something a default must be Cancel, not OK so this must be easily changed...
0
Kalin
Telerik team
answered on 28 Mar 2014, 10:59 AM
Hello Dean,

Thanks again for your feedback. I can see you have logged the item into our Feedback portal, what I can suggest you for now is to follow the item (by clicking the Follow this item button), so once its status is changed you will get notified.

If you have any other questions, don't hesitate to contact us.

Regards,
Kalin
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
Lee
Top achievements
Rank 1
answered on 11 Jul 2016, 04:19 PM

Kalin, 

I would like to set the cancel button as the default but am unfamiliar with how to "exttract the default ControlTemplate of radconfirm" for an asp.net web page. Can you tell me how to do that?

 

0
Yana
Telerik team
answered on 12 Jul 2016, 06:18 AM
Hello,

Please post your question in the corresponding UI for ASP.NET AJAX forum.

Regards,
Yana
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Window
Asked by
Dean
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Dean
Top achievements
Rank 1
Lee
Top achievements
Rank 1
Yana
Telerik team
Share this question
or