Any help would be appreciated!
Here is my PresentationModelCode
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Text; |
using VistaAdmin.Infrastructure; |
using System.ComponentModel; |
using VistaAdmin.Configuration.Properties; |
using System.Windows.Media; |
using System.Windows.Media.Imaging; |
using Microsoft.Practices.EnterpriseLibrary.Logging; |
using VistaAdmin.Composite.Extensions; |
using System.Windows.Input; |
using System.IO; |
using System.Windows; |
using System.Reflection; |
using System.Collections.ObjectModel; |
using Telerik.Windows.Controls; |
using System.Windows.Data; |
using VistaAdmin.Help.Interface; |
namespace VistaAdmin.Configuration.Applications |
{ |
internal class ConfigurationPresentationModel : PresentationModel<IConfigView>, IHeaderInfoProvider |
{ |
private static readonly PropertyInfo HeaderInfoProperty = TypeManager.GetProperty<ConfigurationPresentationModel>(x => x.HeaderInfo); |
private readonly IMessageService messageService; |
private IDynamicHelp dynamicHelp; |
private readonly IApplicationContainer container; |
private RadWindow window; |
private readonly DelegateCommand openWindowCommand; |
private readonly IConfigView view; |
public ConfigurationPresentationModel(IApplicationContainer container, IConfigView view, IMessageService messageService) |
: base(view) |
{ |
this.container = container; |
this.messageService = messageService; |
this.view = view; |
dynamicHelp = container.TryResolve<IDynamicHelp>(); |
openWindowCommand = new DelegateCommand(Open, CanOpenExecute); |
this.window = this.CreateWindow(); |
} |
public string HeaderInfo |
{ |
get { return Resources.Title; } |
} |
public ImageSource HeaderIcon |
{ |
get { return new BitmapImage(ResourceService.GetPackUri("Resources/Config.ico")); } |
} |
private static void Log(string message, System.Diagnostics.TraceEventType severity) |
{ |
LogEntry entry = new LogEntry(); |
entry.Severity = severity; |
entry.Message = message; |
entry.Title = "VistaAdminConfiguration"; |
entry.Categories.Add("Configuration"); |
Logger.Write(entry); |
} |
public ICommand OpenWindowCommand { get { return openWindowCommand; } } |
private bool CanOpenExecute() |
{ |
return !this.window.IsOpen; |
} |
public void Open() |
{ |
if (!this.window.IsOpen) |
{ |
this.window.ShowDialog(); |
} |
} |
private RadWindow CreateWindow() |
{ |
window = new RadWindow(); |
window.DataContext = this.view.DataContext; |
window.Closed += new EventHandler<WindowClosedEventArgs>(window_Closed); |
window.Opened += new RoutedEventHandler(window_Opened); |
return window; |
} |
void window_Opened(object sender, RoutedEventArgs e) |
{ |
//this.window.IsOpen = true; |
} |
void window_Closed(object sender, WindowClosedEventArgs e) |
{ |
//this.IsOpen = false; |
} |
} |
} |
View Xaml
<telerikNavigation:RadWindow x:Class="VistaAdmin.Configuration.Presentation.ConfigurationView" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
xmlns:v="clr-namespace:VistaAdmin.Configuration.Presentation" |
xmlns:p="clr-namespace:VistaAdmin.Configuration.Properties" |
xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" |
xmlns:telerikRibbonBar="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.RibbonBar" |
xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" |
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" |
xmlns:xamlHelpers="clr-namespace:VistaAdmin.Configuration.Domain" |
Header="{Binding HeaderInfo}" |
mc:Ignorable="d" Height="450" Width="450"> |
<StackPanel> |
<ToolBar> |
<Button x:Name="configSaveButton" ToolTip="{x:Static p:Resources.Save}" Command="{Binding SaveConfigCommand}"> |
<Image Source="../Resources/save.png" Width="16" Height="16"/> |
</Button> |
<Button x:Name="configValidateButton" ToolTip="{x:Static p:Resources.Validate}" Command="{Binding DBValidateCommand}"> |
<Image Source="../Resources/db.png" Width="16" Height="16"/> |
</Button> |
</ToolBar> |
<Grid> |
</Grid> |
</StackPanel> |
</telerikNavigation:RadWindow> |
24 Answers, 1 is accepted
Also is there a way to replace the Shell with a RadWindow? I have not looked into or even attempted it yet, but thought since I was here I'd ask.
Thanks!
I changed the method below and boom all works. Not sure how clean it is, but I can somewhat live with it. Only major issue I see is that the view has to be of type RadWindow otherwise an exception would be thrown. Not entirely a seperation of concerns, but pretty close.
If you have a better solution I'd be all ears!
private RadWindow CreateWindow() |
{ |
window = (RadWindow)this.view; |
//window.DataContext = this.view.DataContext; |
window.Closed += new EventHandler<WindowClosedEventArgs>(window_Closed); |
window.Opened += new RoutedEventHandler(window_Opened); |
return window; |
} |
Thank you for contacting us.
Could you please send us a sample running project which we can test here locally. The code you sent us seems to be working properly, but it is not enough for us to figure out what the problem might be.
Looking forward to your reply.
All the best,
Konstantina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Could you please send us a sample project that reproduces the issue? This way we will be able to investigate what the problem is and help you resolve it.
Sincerely yours,Miroslav Nedyalkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Thanks again and excuse me if the problem was something too basic, but i am new on this.
I'm glad to hear that you solved the problem.
All the best,Miroslav Nedyalkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Q1. Im using a radwindow in my application. How can I bind 'Enter' and 'Escape' keyboard press events on radwindow using MVVM design pattern
Q2. In my application, Im using a gridview template column which has a button. I want to execute a custom Icommand event on this button click but the problem is that the Icommand is not getting invoked through bindings in xaml. The design pattern used is MVVM. Could you please help me with it
If you need to handle the Enter and Esc keys you could use InputBindings and add KeyBinding for those keys with the respective commands. For more information about this approach you could refer to the following article - http://msdn.microsoft.com/en-us/library/system.windows.uielement.inputbindings.aspx.
If you want to use the built-in feature of the RadWindow control that allows you to declare some buttons to be Accept and Cancel response buttons, you need to add buttons as content of the window and set the RadWindow.ResponseButton attached property to them. When you do this, these buttons will be automatically clicked when the user press the Enter or Esc key and you could either hook to the Click event or to put a commands to these buttons.
We will need some more details about about the second question - of which view-model is part the command you need to bind to; what binding do you use; in which template is this button(different templates have different DataContext). If you could open a support ticket and send us a sample project this could be very helpful.
The most likely cause of this problem could be that the DataContext in the template you use to put the button is not of the type you expect it to be.
Miroslav Nedyalkov
the Telerik team
Thank you for your response to my queries. support ticket ID for my application is: 409503. Here are a few comments from my side :
For Question 1, my scenario is that Im using the radwindow in silverlight with MVVM design pattern.
In this case how do I access inputbindings / keybindings for radwindow in silverlight
For Question 2, please find the attached code solution for the exact scenario of using button in silverlight radgrid
In the attached application, you will notice that Im able to bind the button command in radgrid column with the help of static resource (by setting the same datacontext for grid and button as mentioned by you in your response)
My concern is that when I click the button(placed inside the 2nd column of a row), the current row of gridview is not getting selected.
As a result, im not able to get the selected user on button command whereas when I specifically select the entire row and then click on the button, the correct user gets diaplyed.
Looking forward to your response.
Thank you !
Attached you can find a sample project that demonstrates how to bind the Escape & Enter keys with InputBindings in RadWindow control.
George
the Telerik team
You
can use CallMethodAction action for invoke the show
method of RadWindow.
This for example show the RadWindow (ErrorListWindow) on hyperlinkbutton click
Define:
xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
<
HyperlinkButton
VerticalAlignment
=
"Center"
Content
=
"{Binding ConnectionStateDescription}"
Width
=
"60"
HorizontalContentAlignment
=
"Left"
>
<
ToolTipService.ToolTip
>
<
TextBlock
Text
=
"Logout"
telerik:LocalizationManager.ResourceKey
=
"Map_StatusBarConnectionTooltip"
/>
</
ToolTipService.ToolTip
>
<
i:Interaction.Triggers
>
<
i:EventTrigger
EventName
=
"Click"
>
<
ei:CallMethodAction
MethodName
=
"Show"
TargetObject
=
"{Binding ElementName=ErrorListWindow}"
/>
</
i:EventTrigger
>
</
i:Interaction.Triggers
>
</
HyperlinkButton
>
Can anyone tell me why this trigger only works once on a combo box? When I select the first element (value of 0) the RadWindow displays as expected. Then when I change the value away from the first item, then back, the RadWindow does not open.
Also, I copied the Hyperlink code from the previous post and added it there as well. This will open the window on every click. But if I click on it, then select the first item in the combo box, the RadWindow wont open!
<
ComboBox
x:Name
=
"cbManufacturers"
Margin
=
"10"
SelectedItem
=
"{Binding Path=SelectedManufacturer, Mode=TwoWay}"
DisplayMemberPath
=
"Manufacturer"
SelectedValuePath
=
"ManufacturerID"
ItemsSource
=
"{Binding Manufacturers}"
>
<
i:Interaction.Triggers
>
<
ei:DataTrigger
Value
=
"0"
Binding
=
"{Binding Path=SelectedValue, ElementName=cbManufacturers}"
>
<
ei:CallMethodAction
MethodName
=
"ShowDialog"
TargetObject
=
"{Binding ElementName=NewManufacturerWindow}"
/>
</
ei:DataTrigger
>
</
i:Interaction.Triggers
>
</
ComboBox
>
<
telerik:RadWindow
ModalBackground
=
"#cc111111"
x:Name
=
"NewManufacturerWindow"
Background
=
"Gray"
WindowStartupLocation
=
"CenterScreen"
Header
=
"Add CPU Manufacturer"
Visibility
=
"Collapsed"
>
<
StackPanel
Orientation
=
"Vertical"
VerticalAlignment
=
"Center"
HorizontalAlignment
=
"Center"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
sdk:Label
Content
=
"New Manufacturer Name"
Foreground
=
"White"
/>
<
TextBox
Text
=
""
x:Name
=
"txtNewMake"
Width
=
"150"
Margin
=
"10"
/>
</
StackPanel
>
<
StackPanel
Orientation
=
"Horizontal"
HorizontalAlignment
=
"Right"
Height
=
"30"
Margin
=
"10"
>
<
Button
Content
=
"Cancel"
Padding
=
"3"
Width
=
"70"
Margin
=
"3"
x:Name
=
"btnCancelMake"
/>
<
Button
Content
=
"Submit"
Margin
=
"3"
Width
=
"70"
x:Name
=
"btnSubmitMake"
/>
</
StackPanel
>
</
StackPanel
>
</
telerik:RadWindow
>
The problem is that the RadWindow control doesn't support to be placed in the XAML of the Page/Window with the other controls. Once the Window is opened for the first time it is removed from the layout and this breaks the binding with ElementName. You could execute method from your code-behind class and there to create (or find) a window and show it.
Hope this helps!
Greetings,
Miroslav Nedyalkov
the Telerik team
I have a query regarding the radtreeview. In my scenario, Im using a radtreeview to show an some data and on enter key press I need to transfer the selected item from treeviw to an adjacent radgridview control. The only problem Im facing in this sample is that when I press enter on a node, the node gets collapsed and child elements are not seen anymore. So just wnated to know is there any way out with which I could disable node collapsing on enter key press ?
Thanks a lot !
Anjani
Please consider the approach bellow and let me know how it works for you.
<
Grid
>
<
telerik:RadTreeView
PreviewKeyDown
=
"RadTreeView_PreviewKeyDown"
PreviewCollapsed
=
"RadTreeView_PreviewCollapsed"
>
<
telerik:RadTreeViewItem
Header
=
"Item 0"
>
<
telerik:RadTreeViewItem
Header
=
"Item 0.0"
/>
<
telerik:RadTreeViewItem
Header
=
"Item 0.1"
/>
<
telerik:RadTreeViewItem
Header
=
"Item 0.2"
/>
</
telerik:RadTreeViewItem
>
<
telerik:RadTreeViewItem
Header
=
"Item 1"
>
<
telerik:RadTreeViewItem
Header
=
"Item 1.0"
/>
<
telerik:RadTreeViewItem
Header
=
"Item 1.1"
/>
<
telerik:RadTreeViewItem
Header
=
"Item 1.2"
/>
</
telerik:RadTreeViewItem
>
</
telerik:RadTreeView
>
</
Grid
>
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public
partial
class
MainWindow : Window
{
private
bool
isEnterKey =
false
;
public
MainWindow()
{
InitializeComponent();
}
private
void
RadTreeView_PreviewKeyDown(
object
sender, System.Windows.Input.KeyEventArgs e)
{
this
.isEnterKey = e.Key == System.Windows.Input.Key.Enter;
}
private
void
RadTreeView_PreviewCollapsed(
object
sender, Telerik.Windows.RadRoutedEventArgs e)
{
e.Handled =
this
.isEnterKey;
this
.isEnterKey =
false
;
}
}
Best wishes,
Kiril Stanoev
the Telerik team
Forstly let me tell give you some more information about my scenario :
1. Im using MVVM pattern in my silverlight project which means Im supposed to keep my code behind clean
2. I have an itemsource bound to my treeview and I dont have specific treeview items binding
3. The telerik version that Im using is 2011.1.405.1040 which does not support
PreviewKeyDown
event.The template for my treeview is :
<telerik:HierarchicalDataTemplate x:Key="NodeTemplate" ItemsSource="{Binding Children}" telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}"> <StackPanel Orientation="Horizontal"> <Image Source="{Binding Image}" Margin=" 0,0,6,0" Height="20" Width="20" Style="{StaticResource IconImage}" /> <TextBlock Text="{Binding Path=Name.OrganizationElement.Name}" FontFamily="Verdana" FontSize="11" Foreground="Black" FontWeight="Normal" /> </StackPanel> </telerik:HierarchicalDataTemplate>
My treeview looks like this :<telerik:RadTreeView x:Name="OrganisationtreeView" SelectionMode="Single" IsTriStateMode="True" ItemsOptionListType="CheckList" ExpanderStyle="{StaticResource ExpanderStyle1}" ItemTemplate="{StaticResource NodeTemplate}" ItemsSource="{Binding TreeData1}">
Waiting for your reply..
Anjani !
Thank you for the clarification. Since this is a RadTreeView for WPF thread, I assumed you were having a WPF application. Unfortunately this scenario is not supported in RadTreeView for Silverlight, due to the fact that Silverlight does not provide Preview keyboard events. RadTreeView's PreviewCollapsed event gets fired before the KeyDown event which makes it impossible to handle the PreviewCollapsed event based on which key is pressed.
Kiril Stanoev
the Telerik team
Thank you for response to my query. I guess for the time being, I will have to live with the inbuilt behaviour of radtreeview for silverlight.
I have another query regarding radwindow. I tried putting my query in the relevant thread of radwindow but every time it gives 'telerik server error' to me . So here is my question :
My question is regarding controlling the size of radwindow in silverlight. Im using MVVM design pattern where I was trying to bind the
MinHeight and MinWidth of radwindow. Basically I have radwindow being launched in 2 modes with different sizes. So I want to resrict the minwidth and minheight in both modes separately. I thought the best way out would be to bind these properties in xaml and set their mode as twoway. But when I try to run my project I get an exception of ".. trying to access protected memory". Could you tell me if there is any way by which I could control the minimum height and width of Radwindow ?
Thanks a lot !
Anjani
I tried to reproduce the problem you are experiencing, but I couldn't. Please refer to the attached example which opens a RadWindow with bound MinWidth and MinHeight to a data object.
Greetings,Miroslav Nedyalkov
the Telerik team
Hello Telerik Team,
I am working on Silverlight “RadTreeView” control in a Sliverlight application.
Using Silverlight Rad controls product version 2011.1.0502.1040 .
My "RadTreeView" is attached with an Itemsource.
Now I am trying to Stop the default functionality of "Collapse and Expand" on Enter key press.
Is it now possible to achieve this functionality in Silverlight with the version I am using or new versions?
There are no preview key events in the RadTreeView for Silverlight. So you can inherit from the RadTreeView and override the OnKeyDown event like so:
public
class
CustomTreeView : RadTreeView
{
protected
override
void
OnKeyDown(KeyEventArgs e)
{
base
.OnKeyDown(e);
if
(e.Key == Key.Enter)
{
e.Handled =
true
;
}
}
}
In WPF, the RadTreeView has Preview Key Down/Up events.
On a side note, we suggest you to open a new Support Thread / Forum when your Question is related to Control not recently discussed in the thread.
Petar Mladenov
the Telerik team
Thanks for your solution.
Sample application is working fine at my end.
Actually I was using old version of Telerik product.
Thanks & Regards,
Harpreet Singh.