Create an editable wpf treeview item - c#

I'm checking this page and I like the only answer there is.
Editable WPF treeview item on doubleclick? (with styles?)
But I don't like the idea to use c# lines, Might there be a possible to write that code using XAML?

You can use EventSetter, or AttachedBehavior. But they are assumes that you need c# code-behind.
How to do it in XAML - hard to say. One more possible way - to use x:Code clause to write c# code inside xaml.

You can use CheckBox in the XAML and using its IsChecked property change the Style to the Editable mode

Related

How to make in C# a ListView with custom content just like Android's ListView?

Is there a way in C# where you can design ListView items and use and adapter just like Android has?
I have a UI proposal for my project and it requires this kind of feature.
The look is like this: Project GUI
The RED area indicates the ListView and it has these items which have custom layouts.
Here is the layout of the item: Item Layout
So, every time that the program detects an object it will create an item to the ListView with the preview of the Object.
Yes there is a way. It's not easy but you can. You must set the OwnerDraw property to true. You can then handle the DrawItem event and do your own implementation. Alternatively, use a control like this.
In WPF that job would be much more easy :)

Silverlight-Hiding item in ItemsControl

I have an ItemsControl.I want to hide the Text Box in the ItemsControl DataTemplete on some Flag. But when i access the Text Box in Code Behind File .it gives the error doesn't exists in the current context.Is there a way to do this using SilverLight?
Let's go by parts, in case you are not using MVVM, due to you are using a DataTemplate the Control is not added as usual in the visual tree, so you can do the following, add to the TextBox the LoadedEvent, and create a List in order to have all the TextBoxes inside, and there you can do what you need when you want.
In case you are using Binding with MVVM, you can bind the property of that control, like the Text with Mode=TwoWay or the Visibility with a bool and adding a converter.
That is a general answer to your general question, in case you need more details, please add the specific code you are using.

How to make List<Object> variable appear in DataBinding UI when using WPF in Visual Studio?

I'm in the process of learning WPF and currently exploring data binding. I have a DataGrid control on my form, and in my C# code for the form I have a List<string> variable.
I want to be able to use the Properties UI for the DataGrid in the designer to bind the List<string> to the DataGrid. I cannot figure out what I need to do or where I need to look in the UI to do this.
This is what I am doing:
Click my DataGrid in the UI designer to make it the active control.
Move to the Properties window.
Scroll down to the ItemsSource property.
Click on the field and the UI with Source, Path, Converter and Options pops up.
And when I get to this point I no longer know what to do.
I do not want to accomplish this by writing/modifying XAML. I want to know how it works using the UI.
Having never used the designer before, I can't be totally sure (your use case isn't quite clear either).
That being said, in my designer you
Set the "Binding Type" to "Data Context"
Select the "Custom" text box (needed for me because it doesn't see my DataContext)
Type the name of your property in the "Path" field (you can only bind to Properties)
Hit OK.
Note that this is the same as writing in XAML:
<DataGrid ItemsSource="{Binding MyItemCollection}"/>
<!-- or --!>
<DataGrid ItemsSource="{Binding Path=MytItemsCollection}"/>
There's a reason no one uses the designer....
The other options are more "advanced" binding concepts that you don't normally use on ItemsSource properties.
Note that DataGrid is a poor choice for displaying strings. ListView or ListBox are much better choices, as they don't assume your information has multiple pieces (like DataGrid does).
I understand not liking XAML, as it really intimidated me at first, but I will quickly say that it is a powerful tool. I am not sure how to do it through the designer, but in C# let's say you name your DataGrid 'myDataGrid' and your List is named 'stringList'. It is as simple as the following:
myDataGrid.ItemsSource = stringList;
and the data grid is now bound to your string list.
Thanks for asking the question! The properties window is so underrated.
First you must set the DataContext.
It's in the common section of the properties window. Set the data context to whatever view model you need. If you don't have a VM and the List is in the code behind, set the data context to relative source self.
Next in the Path write the name of your List.
Also, you may want to use ObservableCollection instead of List so your objects are updated in the UI as they change.

Checkbox to look like expander

I"m trying to make a checkbox / button type thing that looks exactly like the expander button. I've written my code for IsChecked, but was hoping not to use the checkbox. I'm not sure if this makes any sense... how to do that in xaml?
The best way to make a CheckBox look like an Expander is to modify the ControlTemplate of the CheckBox (I assume you're already trying this).
Therefore I would have a look at the ControlTemplate of the Expander and try to modify it to use the data of the CheckBox class (or maybe an approach in the over direction would be easier, you will have to find out).
To see, how the ControlTemplate of the Expander is defined you can use Expression Blend to extract the template or have a look at this MSDN page.

looking for text control that is easy to data bind and text highlight wpf

I am looking for some control that can do following 2 :
1.highlight some of the text in different colors.
easy databind.
checked richtextbox - but it is hard to databind with it.
checked textbox but it problem to text hight light with it.
any suggestions
Use the RichTextBox - or even better the Extended RichTextBox here (it allows easy DataBinding): http://wpftoolkit.codeplex.com/wikipage?title=RichTextBox.
If you don't want to have to include another control you can create an AttachedProperty to make it possible to bind to the built in RichTextBox. Check this out here: http://michaelsync.net/2009/06/09/bindable-wpf-richtext-editor-with-xamlhtml-convertor

Categories

Resources