Search code examples
c#wpfmvvmtelerikradwindow

Bind the text field content to Ok button of RadWindow


In my application built on MVVM architecture using C# & WPF, I'm using the RadWindow to prompt the user to enter the filename with Ok & Cancel options.

I want to be able to enable/disable OR visible/invisible the OK button on the basis of user input.

Ex: Filename entered -> Ok button enabled/visible

Filename empty -> Ok button disabled/invisible.

How can I acheive this behavior?


Solution

  • The Telerik RadPrompt window has a custom Template which contains a TextBox and two Buttons. To enable or disable the Button based on the input of the TextBox, you can add a Binding to the IsEnabled property of the OK Button:

                        <telerik:RadButton x:Name="OK"
                                Command="{x:Static telerik:WindowCommands.Confirm}"
                                telerikNavigation:RadWindow.ResponseButton="Accept"
                                MinWidth="70"
                                IsTabStop="True"
                                TabIndex="1"
                                HorizontalAlignment="Right"
                                telerik:LocalizationManager.ResourceKey="Ok"
                                Margin="0 10 8 8"
                                IsEnabled="{Binding ElementName=PromptTextBox,Path=Text.Length}" />