I am trying to switch off the grid visibility of a RadDiagram I have.
I am creating a User Control using Telerik controls within a Silverlight Project (sharing the control with a WPF Library).
It seems that RadDiagram Property is not found. (RadDiagram Commands - Found property here)
PS: I am creating and filling the shape programmatically. Therefore, I need to an approach to switch the grid off that apply to Style attribute in Resource Dictionary or a simple programmatic property set / function call.
Thanks,
The way to turn off the BackGroundGrid or BackGroundPageGrid is to use these attached properties:
<telerik:RadDiagram x:Name="diagram" Margin="30"
primitives:BackgroundGrid.IsGridVisible="False"
primitives:BackgroundPageGrid.IsGridVisible="False"
where primitives is defined like so:
xmlns:primitives="clr-namespace:Telerik.Windows.Controls.Diagrams.Primitives; assembly=Telerik.Windows.Controls.Diagrams"
If you need to bind the command for switching the BackGroundGrid On / Off , you can use this syntax:
<telerik:RadButton Command="telerik:DiagramCommands.SwitchGridVisibility"
CommandTarget="{Binding ElementName=diagram}"/>
Programmatically in code-behind here is how it is done:
Telerik.Windows.Controls.Diagrams.Primitives.BackgroundGrid.SetIsGridVisible(this.myDiagram, false);
Source: Switch Grid Visibility
Related
I need my application to be notified when style is changed of a control. I need to to do some actions when the style is changed of a WPF control. Can I apply some eventtriggers or notify is some way.
Best Regards
There are a few possible solutions.
First you could subscribe a change handler to the Style property of your control if want to get notified somewhere in your C# code:
DependencyPropertyDescriptor.FromProperty(Button.StyleProperty, typeof(Button))
.AddValueChanged(btn, (s, e) =>
{
// Style has changed.
});
(Don't forget to call .RemoveValueChanged() after you're done.)
Another way would be to create a Binding with a source path set to the Style of your control. The binding target could for example be some kind of custom control or a ViewModel where you want to react to the change. Or if you don't have any of these available, you could just set the binding target to some Tag property and use a ValueConverter to intercept the change using something like Tag="{Binding Style, ElementName=btn, Converter={StaticResource MyStyleInterceptor}}".
You could also create a custom attached property for this purpose if you don't want to abuse Tag.
I implemented some generic CustomControls in WPF, for instance an AutoCompleteTextBox.
Now, I'd like to implement a generic ViewModel library, in order to perform the databind of these controls.
Now I defined one attached property named CDataSource, that specifies the source of the data to bind within the control.
My question is : Is it possible, that the CustomControl passes to the ViewModel the CDataSource value? In this way the ViewModel may populate the control on the basis of the CDataSource property.
Thanks in advance
This seems like a strange request to me. You don't want any dependency on your view model from within your custom control. Instead, you would normally have a dependency property on your custom control which is the ItemsSource, and then you would set the value of this from your view in XAML.
This is how the AutoCompleteBox included in the WPF Toolkit operates.
I'm creating a WPF custom control as an auto learning exercise. My control has a ListView inside the template. I wanto my control user be able on defining the needed columns in his own Xaml, but I did not get the strategy on how to pass the columns to the inner listview since binding with FindAncestor complain that "Columns" is not a DependencyProperty.
Wekk the questions are:
How to achieve bind a property from xaml to the template when it is not a DP
Correct my design: I think there is something wrong: if someone would change completely my template, how should I let him use the Column collection ?
why not inherit from ListView directly? Then you have all the properties you need for the ListView and can also add you own properties to the class.
Then you can apply a custom Style to your control to make it look like you want. (Here you have a basic ListView Style that you can use and expand to your needs)
Sometimes binding to a property that is not a dependency property can be solved using the Binding Mode OneWayToSource
Have you tried that?
I'm using the 'Extended WPF Toolkit' ( http://wpftoolkit.codeplex.com/ ),
and for my own purposes I've created a generic version of its NumericUpDown control called GNumericUpDown< T > which actually lets me specify what type to use, ie. GNumericUpDown< int >.
(This is done to make sure the control respects the appropriate Min/MaxValues of the wanted type)
To be able to use different types from Xaml, I've created a new project with specific derived versions, f.e. NumericUpDownFloat which is derived from GNumericUpDown< float>.
But when I use the NumericUpDownFloat in XAML, nothing is displayed.
I assume this is because there's only a style specified for the WPF Toolkit's NumericUpDown in the Generic.xaml resourcedictionary of the WPF Toolkit project.
So how can I make all my specific versions (NumericUpDownInt, NumericUpDownByte, ..) actually use that style ?
You should get the latest source code for the Extended WPF Toolkit. The updated NumericUpDown control allows you to specify what data type to use in the editor. The following code specifies to use an Int32 as the data type instead of the default double. As you can see this is done by setting the ValueType property on the NumericUpDown control.
<extToolkit:NumericUpDown Grid.Row="1" Value="{Binding Age}" Increment="1" Minimum="18" Maximum="65" ValueType="{x:Type sys:Int32}" />
This will eliminate the need for the seperate project with specific dervied controls.
By default when you make any type of custom control, WPF puts this in the static contructor of the class for you:
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));
This tells WPF that you are going to supply a theme for it somehow. By default, a Themes folder will be created at the root of the project, with a Generic.xaml file created with the CustomControl1 style and control template put inside of it.
If you want to tell WPF you will be override the style (or really, overriding the default style key dependency property), you just put that line in you static constructor. If you want it to fall back to whatever it's parent style is, you just omit that line and something like this:
public class SuperAwesomeControl : Border
{
....
}
Will always look like border by default.
I'm building a menu using Prism (using a trtelerik tree view with hierarchy data templates but hopefully the details don't matter) and I'm trying to set up a Click.Command on each menu items bindings that will all call the same delegate command which is defined in the view model. The menu is built up out of items which I don't really want to put any references to the command in.
How do I bind the command to each of these items in xaml? I've looked around and it looks like in WPF I could use a relative source binding and find ancestors but there doesn't seem to be a way of doing this in silverlight. Can I setup the delegate as a static resource somehow? I don't think I can create a static resource to the view model as this uses Unity to resolve paramters to it's constructor.
One option is to bind to the UserControl's DataContext (or any other control's DataContext) via ElementName binding.
<UserControl x:Name="Control" xmlns:Cal="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"...
Cal:Click.Command="{Binding ElementName=Control, Path=DataContext.SomeVMCommand}"
Here's a similar post.