|
Well, setting the groupname solved the issue of them not acting like radio buttons.
Before I implemented this template, I had the telerik:RadRadioButtons defined explicitly in the XAML, and the command was working, as was the grouping without setting the group name. So given that, I know the DC is set right.
So, I'm still not getting the Command to work right at this point.
Everything makes sense in someone's mind
|
|
|
|
|
Oh duh... I must have been smoking crack earlier...
You are inside of the DataTemplate, so {Binding} is pointing to your item, not the VM. In this case, its MenuButtonData.
Now, you wanted to be like the cool kids and use MVVM , so you made your life a lot more difficult because you can't use RelativeSource / FindAncestor to get to where the property is.
I guess you could make the command a static property and refer to it that way, but then how would the static handler get to your VM?
Or you could try use RelativeSource / FindAncestor to get to your view if it has a reference to the ViewModel and then access the property through there. However that wouldn't be proper MVVM.
Your other option (which is what I do in my code) is to subscribe to the ItemContainerGenerator messages and when the container is generated for each item, use FindName to get to the RadioButton and hook up the command then.
The simplest way is to have the command in your view, but that ain't the best MVVM and it wouldn't really jive with your VM.
Its messy any way you do it.
|
|
|
|
|
Another idea I just had was that you can add a ref to the command inside of your MenuButtonData class and then you can use simple {Binding} in your DataTemplate and your MVVM wouldn't be broken.
You *would* have a random reference to a random command in a random place, but your other options are a lot messier.
And actually, maybe a command reference inside of MenuButtonData isn't so random...
|
|
|
|
|
This may be a really dumb response (I have not used radio buttons in SL yet, let alone Teleriks) but can't you add an IsChecked property to your observablecollection and track the change event on the list?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Try your binding like this:
<telerik:RadRadioButton Command="{Binding DataContext.SelectedTemplate, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"
HorizontalContentAlignment="Center"
Height="175"
Width="120">
The DataContext of the items in your itemscontrol get set on the bound item, so you have to reference your itemscontrol as source.
modified on Friday, March 25, 2011 2:26 AM
|
|
|
|
|
That did it. Thank you!!!
The only question now is how to determine which RadioButton was clicked?
Everything makes sense in someone's mind
|
|
|
|
|
Its not in sender, OriginalSource, etc? That'll just get you the RadioButton though. I'm thinking one step ahead of you here... you aren't interested in which RadioButton was clicked, you are interested in which MenuItemData was selected, right? In that case, just use CommandParameter={Binding} to pass your MenuItemData into your command handler.
|
|
|
|
|
Ok, here's the XAML:
<telerik:RadRadioButton Command="{Binding DataContext.SelectedTemplate,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"
CommandParameter="{Binding}"
HorizontalContentAlignment="Center"
Height="175"
Width="120"
GroupName="TemplateButtons">
and here's the C#:
private ICommand _SelectedTemplate;
public ICommand SelectedTemplate
{
get
{
if (_SelectedTemplate == null)
_SelectedTemplate = new RelayCommand(SelectedTemplateExecuted, SelectedTemplateCanExecute);
return _SelectedTemplate;
}
}
public bool SelectedTemplateCanExecute()
{
return true;
}
public void SelectedTemplateExecuted()
{
loadView(InnerViews.Presentations);
}
How/where is the MenuItemData reference passed?
Everything makes sense in someone's mind
|
|
|
|
|
This now works.
First the XAML:
<telerik:RadRadioButton Command="{Binding DataContext.SelectedTemplate, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}"
CommandParameter="{Binding Path=DataContext, RelativeSource={RelativeSource Self}}"
HorizontalContentAlignment="Center"
Height="175"
Width="120"
GroupName="TemplateButtons">
Now the code behind:
private ICommand _SelectedTemplate;
public ICommand SelectedTemplate
{
get
{
if (_SelectedTemplate == null)
_SelectedTemplate = new RelayCommand<MenuButtonData>(SelectedTemplateExecuted, SelectedTemplateCanExecute);
return _SelectedTemplate;
}
}
public bool SelectedTemplateCanExecute(object Parameter)
{
return true;
}
public void SelectedTemplateExecuted(object Parameter)
{
}
Adding the Type qualifier to the RelayCommand and setting up the CanExecute and Executed methods to receive the parameter is what did it. Now, when a radiobutton is clicked, it's bound data item is passed to the command methods.
Many thanks to all of you.
Everything makes sense in someone's mind
|
|
|
|
|
my colleague at work has some helper class for it, but I'm not at work anymore so can't look at it right now...
but I think he has a generic wrapper class Option<t> with an IsSelected property
So maybe you could try to add an IsSelected property to your MenuButtonData class and bind it to your
IsSelected of your radio button?
This is just guessing as I don't even know the RadRadioButton control.
Would CommandParameter={Binding} return the control or DataContext?
Wouldn't it need to be CommandParameter={Binding Path=DataContext, RelativeSource={RelativeSource Self}} to return the MenuButtonData?
Again just guessing, don't even have VS at home
|
|
|
|
|
Thats kind of a slick way to get to the VM. I'll have to remember that.
|
|
|
|
|
Hi
I have trouble getting WPF binding to a simple CLR Property to work (Visibility=Collapsed)
<Button Name="btnSomeCmd" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="3" Click="btnSomeCmd_Click" Width="25px" Height="25px" Visibility="{Binding Path=IsSomeCmdVisible}" >
public partial class SomeUserControl : UserControl
{
...
public Visibility IsSomeCmdVisible
{
get { return Visibility.Collapsed; }
}
...
}
sigh, WPF makes it so hard to get simple things work. (I got it working with dependency property but simple CLR... anyone please write an article on this)
dev
|
|
|
|
|
God damn, got it:
<UserControl x:Class="..."
x:Name="BasicConfigCtrl"
...
Visibility="{Binding Path=IsSomeCmdVisible, ElementName=BasicConfigCtrl, Mode=OneWay}"
...
ElementName references UserControl's x:Name tag.
dev
|
|
|
|
|
The easy way to do this is to have a boolean condition (depending on the effect you are trying to achieve), and then use a value converter. Have a quick google for BooleanToVisibilityConverter[^] to find out more about it.
|
|
|
|
|
Hi,
I bought this book recently and going through the chapters...
Question:
I am unable to login when running the solution in chapter 4.
Has anyone had the same issue please?
Thanks
|
|
|
|
|
That is one of the most obscure question I have run across.
You expect someone to guess the book (or do you think there is only 1 book on Silverlight/WPF). Who the hell knows what is in chapter 4 of your mystery book!
You presumably have the source code for the project and can therefore debug it and work it out!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
Thanks for replying...
Please note that the name of the book is in the subject.
Regards
|
|
|
|
|
|
Hi all,
In my application i m willing to access a network folder.i m using "FileAuthorizationModule.CheckFileAccessForUser(strLocation, userToken, "GET" ) = True )".Wehn the file is in server then there is no problem but when it is in other system then the following error occur-
"virtual path outside of the current application is not supported.parameter name:VirtualPath"
Any clue?
|
|
|
|
|
Well, for a start you've posted an ASP.NET question in the WPF forum. One of the reasons that the forums exist is so that questions and solutions can be easily searched for, based on previous questions of the same type. If this is bypassed, then people have no idea where to go to find the answer, so the same answer ends up being given time and time again.
I will say though - with a judicious use of Google, you will readily be able to identify the solution to your problem. Just type the error message in to the search engine of your choice, and take a look at what other people have done when they encountered this problem.
|
|
|
|
|
I'm working on an installation window for our software. I'm having an issue trying to get it to run off of a cd or dvd. I've built a button that is to run our license installer but when it is burnt to cd or dvd it says it can't find the file. Here's what I'm using to launch the install:
i:EventTrigger EventName="Click"
ei:LaunchUriOrFileAction Path="\Installation Window\Installation Window\License\License.exe"
Any ideas?
|
|
|
|
|
The obvious question is, have you verified that this path exists on the CD? If it does, check that LaunchUriOrFileAction isn't doing something "clever" to the path, so that what you think is being run is actually what is being run (an easy way to do this is to temporarily write the path that's being launched to the event log).
|
|
|
|
|
Hi,
I have been reading alot regarding this topic.
The only difference I was able to spot while reading was that the page is used if you want to navigate from one page to another.
I have done several tests in a test silverlight application.
In the mainpage.xaml which is a usercontrol i have placed linkbuttons.
These linkbuttons refer to either usercontrols or pages.
The navigation seems to work whether i go to a usercontrol page or a silverlight page (navigation page).
And the history, i.e. go back and forward buttons also work in both pages.
So, what is the main difference please?
Thanks
|
|
|
|
|
The Page is actually an inherited UserControl . The big difference between them is that the Page is eligible to be loaded into a Frame , and you can set the Title , which sets the browser title (something you can't easily do in a UserControl ).
|
|
|
|
|