I made a user control, and in my control I have "Title", graphically "Title" is a TextBlock, but I want those who use mon control will have the option to change it, so, the first idea is the create a property "TitleTemplate" that inherits from "DataTemplate", I'm just following the wpf logic, but I cant find any tutorial that can help me.
I think, u should read more about TemplateBinding and ContentPresenter.
I suggest u read this articles:
Using Templates to Customize WPF Controls
and
Dr.WPF
After some research, I have concluded that the best way is the create a CustomControl, not a UserControl, because, my control is not a composition of other controls, I hope that helps.
Related
I am curious how I can add a property to add functionality to a control. Currently I am just extending controls, but I was curious if it is possible to add a property to add functionality to a control. Like for example the ToolTipService. You can add that to controls. Would it be possible for me to add a property to add a contextmenu without having to extend a textbox lets say? I know about behaviors, but is it possible to do that as a property? Let's say I add a property IsContextMenuBehaviorAdded="True" and that will just attach a behavior, or just add functionality. Any help would be greatly appreciated. Thanks in advance.
If you are looking to add a context menu to a control then you can do that with the Silverlight Toolkit which contains a ContextMenuService.
I wrote a user control for my project. Now I want to have a template for it where everything is moved around.
How would I go about doing this? I'm looking and it seems impossible? I see many paths on how to do this but what would be the best way?
Some ideas I have:
Rewrite the user control as a control so it can be templated
Create a second user control, but have it databind to the same viewmodel
You should take the first option. Rewrite the original control as "Silverlight Templated Control" borrowing from the original UserControl xaml to help you set up the initial default template.
Review the MSDN topic: How to: Create a New Control by Creating a ControlTemplate
This forms a good basis. However that example doesn't make enough use of TemplateBinding, in your implementation you should make wider use of that.
I think all WinForm controls have a Tag property which I found very convenient on occasions. However, this Tag property seems to be gone for WPF controls like DataGrid. Can anybody explain why? Is there a better way in WPF to accomplish this?
WPF controls do have a Tag-property (Because of the base-class). However with the concept of the DataContext, the tag-property is not anymore very important.
The Tag property misses meaning. You can use Attached Properties to create more semantic properties on any control.
I am new to both Silverlight and Blend 4.
I am trying to make a Image Gallery, where u click on the image and it shows details of the same.
I used VisualStateManager to get a mouseOver and mouseOut effect to the thumbnails. and here is wat i want. I want to add the VisualState's to all my thumbnails through Style. (I had seen this in some forum, but i cudnt figure it out how he did it.)
Here is wat i want:
I have set of thumbnails to, which need to scale up on MouseOver and come back to normal on MouseOUT. I created a VisualStateManager States.
But i want to use the state as a
common state for all the thumbnails
and apply it to the thumbnails through
Style.
Is this possible? If so how?
If not? then is how can i achieve it.
Would be really thankful to any one who can help me :) just that this is a bit urgent. :(
MSDN documentation says that you should be able to add the VisualStageManager XAML tag to any control which inherits from UIElement and accepts child controls.
It seems to me then that the best way to do this is to create a UserControl for your thumbnail and set the VisualStateManager there. You can then reuse that UserControl.
More reading material:
MSDN UserControl documentation
Adding behaviour to stock controls
I am creating a custom control by deriving TextBlock, my intention is to do some custom rendering based on some dependency properties. However the OnRender method is sealed on TextBlock. Although I can get my work done by overriding OnRenderSizeChanged, this is not correct. Any ideas on how can i do it the right way?
Thanks in advance.
In WPF you normally work with styles or Control templates to change the appearance of a control. You can download templates for all controls from Microsoft and play around with them.
Read more here:
http://msdn.microsoft.com/en-us/library/system.windows.controls.controltemplate(v=VS.100).aspx