This may seem familiar to you but I have a problem creating a custom List Box with custom style as well. I can only do one of them at the same time... I can't use both. and another thing is that could you tell me how to add the custom listboxitem in c# code so I could easily add it to the program?
what I mean is that for example if you put an image before the text of listboxitem and then give it an style, but all thease must be done for all items.
thanks to all
First, what have you already tried out? Are you expecting SO users do the work for you?
Listbox tag has a ListboxItemTemplate. For that you can implement a DataTemplate has a StaticResource and put whatever you want inside.
Check the documentation on MSDN.
https://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemtemplate(v=vs.110).aspx
Related
Is there any way to replace one control with another?
I have a library from a vendor that uses a TextBox and I would like to change it to a RichTextBox.
Can I maybe set up a Style with a TargetType=TextBox and assign it to RichTextBox?
I do have access to the vendor code, but putting the replacement in the parents Resources would be much easier than updating their code each time they have a new release.
Is this even possible?
Thanks!
Without knowing more about the control(s) in question, I would recommend using the "Edit Template > Edit a copy" in VS or Blend and changing the TextBox to a RichTextBox. This should leave the rest of the template intact.
If that doesn't work, please post the ControlTemplate and/or Style code you used, and maybe a screenshot of the vendor control.
I feel like I'm going to reinvent wheel so I would like to know if WPF has bult-in support for what I'm trying to achieve. I'm building an app that will allow people to enter some text in a textbox, and then see it formatted in a textblock.
I would like that the user be able to format the text himself by inputing things such as
This [BusinessSpecificStyle] is [/BusinessSpecificStyle] a sample text
My purpose is to be able to easily change the presentation of all my documents by simply changing the underlaying rules in BusinessSpecificStyle. However I don't know what is the best way to implement that with WPF. I was thinking of using a BBCode parser like this one but supposing I go that way, I don't see how I will be able to convert the resulting XAML into TextBlock children programatically, and I seriously wonder if there isn't some kind of built in support for that.
Thanks for your help
IValueConverter is what you are looking for.
Create the converter and format your text based on the bindings passed from the XAML.
You can get multiple samples over the net for creating IValueConverter. Refer to the link here and here to get you started.
Not sure if you are asking for Converter here. To me it reads that you want to control the style of a block of text depending on some background and common style?
If that is the case, you want to set the inlines of your text block to seperate your text into run elements, which can reference a specific style resource.
<TextBlock>
<TextBlock.Inlines>
<Run>This</Run>
<Run Foreground="{StaticResource BusinessSpecificStyleForeground}">is</Run>
<Run>a sample text</Run>
...
in this case, you create a resource which defines the binding styles for run or bind the Style in it's entirety.
Apologies if I am making up a new question, I see you've marked an answer but wanted to add this just in case.
I need a custom control element. I prototyped it and here it is on the picture. I think it is pretty self-explanatory. Could anyone suggest me how to organize it? I am not a WPF guru so if it will be working solution I'll better use it instead of doing by myself.
Sadly I can't post image, so it is here: http://imageshack.us/photo/my-images/521/control1.png/
Should I use datagrid with custom templates?
If so my question is how to populate row cells with custom contols and how to handle events on this controls to operate the RowId number?
How to apply custom templates for any individual cells? I found articles where templates applyed only for entire grid or column.
If anyone can help with this I would really appreciate it :)
I would suggest you to use ListView in grouping mode (with styles and templates)to accomplish this. Here are few samples doing similar to what you want to achieve -
ListView with grouping (In GridView mode)
Empty groups in WPF ListView
MSDN is also having one sample for this -
ListView Grouping Sample
I would personally use a TreeView. If your classes are already grouped properly ,you can then use HierarchicalDataTemplates to define how the TreeView works with each type. This will involve templates and triggers. Really, this will be mostly xaml, with very little event coding.
Being a beg. me facing a problem. Please help me out.
I have created a "Style" in xaml and named it "CustomButton" for creating a button( which consist of Two Images and one Textblock) and want to load one of the image and text to TextBlock only at runtime i.e by code behind so that ill be having diffrent image and differnt text for each button. Actully, me need create an array of Buttons of the same style but diff. Image.
Style mystyle = (Style)Application.Current.Resources["CustomButton"];
Setter templateSetter = (Setter)mystyle.Setters[0];
btnNext.Style = mystyle;
i created "style" in App.xaml and in code behind i call name style.
hope this help !
Thongaduka !
Depending how much XAML you want, you need to either create a custom UserControl that inherits from Button, with a DependencyProperty for the background.
Or you can specify a ImageBrush for the Background property, and use that, along with the Content property, in your custom style. The ImageBrush approach is going to require some 3-4 lines of XAML per button.
And I wouldn't recommend creating any UI controls from C#, as you can do everything you want to using databindings. If you're attempting to render custom buttons inside a listbox, with a custom background, simple databinding work should do just fine, rather than creating any custom controls or styles.
Feel free to clarify (with code!) what you're attempting to do now.
How can I change properties of some controls in DataTemplate that placed in resource from code?
I use .NET 3.5, so DataTemplate doesn't have Template property.
Take a look at DataTemplateSelectors
--Edit--
I'm sorry I did not understand the question at first, I think the best way would be to write an extra template, that looks the way you want to modify the other one, find it and assign it
to the list control.
Here is a little example