preselect checkboxes in radtreeview silverlight) - c#

I have a silverlight app where there is a telerik radtreeview with checkboxes. The user selects stuff and when the user wants to edit it's selection i need to pre-populate the tree with the previously saved selection.
I found out that I can bind the checkboxes to my viewmodel. But if I choose that scenario I don't use the "built in" checkboxes and lose the tristate logic (autoselecting siblings when selecting a parent and such)
So I am experimenting with trying to get the radtreeviewitem objects from the radtreeview.items collection
http://www.telerik.com/help/silverlight/radtreeview-how-to-iterate-through-treeviewitems.html
The problem is that the radtreeviewitems are only generated when a node is expanded by a user in the ui. So not all items I want to iterate through are present after the control is databound.
I have not found a good way to force the ui to build all the radtreeviewitems so I can iterate through them and set my preselection. I found the links below but it only seems to work with the root node, not the siblings.
WPF: control.ItemContainerGenerator.Status is NotStarted. How do I tell it to start now?
Would you guys also consider rebuilding the "tristate-mode" into your viewmodel logic "dirty"?
How would you go about preselecting checkboxitems in the radtreeview?

This is how I do it :
public static void CheckAllTreeItemsAuto(RadTreeView tree)
{
tree.ItemContainerGenerator.StatusChanged += (s, e) =>
{
if ((s as Telerik.Windows.Controls.ItemContainerGenerator).Status == Telerik.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
{
RadTreeViewItem item = (RadTreeViewItem)tree.ItemContainerGenerator.ContainerFromIndex(0);
while (item != null)
{
item.IsChecked = true;
item = item.NextItem;
}
}
};
}
I didn't experience your problem with the items not generated at the start. (I don't know how you generate your RadTreeView).

When working with the RadTreeView control you need to have in mind that the built-in tri-state logic is designed to work with declaratively defined control and items, only. This means that using this feature in MVVM scenarios will not work as expected.
Since Telerik is aware of that limitation they provided the community with an article demonstrating how developers can use the tri-state logic of a native CheckBox control in MVVM scenarios. You can find the article in their documentation. Also, at the end of the article you can find a link leading to their CodeLibrary where you can download ready to run project demonstrating the described approach.
I hope this information will help you.

Related

How to make an accordion style content holder UWP

So i am trying to make an accordion content holder for an uwp application. I can't find anything resembling what i want to achive in the documentation. Is this someting i need to build from scratch using stackpanels and codebehiend ect ect, or are there tools I can use within the libary which I havent found yet ?
Here Is an example of what i want. When the users clicks on a vaccine name, a content box containg information about that vaccine will dropdown. And if it is click while expanded, it will slide back up and only display the name again. An accordion.
Any suggestions, tutorials, articles on the subject will be much appreciated. Thanks in advance.
There is UWP Community Toolkit available that has an expander control that you may be able to utilize. You can get the code sample from the Windows Store and the source code is on github.
https://blogs.windows.com/buildingapps/2016/08/17/introducing-the-uwp-community-toolkit/#v6cSIzET7QwQOb8O.97
I believe from the answer that you know how to make a ListView using DataTemplate. If not search the documentation for this.
So I believe that the most important piece of the question is about the expanding.
First in your DataTemplate bind Height to your DataModel for example like this:
<Grid Height="{x:Bind Item.Height, Mode = OneWay}">...</Grid>
Then place Clicked (or Tapped if its control doesn't support Clicked) event on that arrow, and handle it in the code like this (Tapped may require different arguments but they'll appear automatically anyway):
Arrow_Clicked(object sender, RoutedEventArgs e)
{
var item = (sender as Button).DataSource as Item;
if (item.Height == 80)
item.Height = 200;
else
item.Height = 80;
}

Navigation bar for hierarchical navigation in wpf

Hi there is a control in asp.net called SiteMapPath i need something similar in WPF to help users navigate back and forth through the application pages ...
does any one know about any third party control or built in features that can help me implement this feature or should i start from scratch
Being able to display journal history can do the trick too
I don't know of any WPF controls that work like the SiteMapPath. You could use a menu or a tab control to load different views onto the page and define the menus/tabs in xml. Below are a couple of links which may help spur you on to some ideas.
WPF XML DataBinding
Bind to XLinq
For Breadcrumbs you may be interested in
code project
stack overflow
Ok i created my own breadcrumb for wpf ...
First of all since all the navigation in my application were based on wpf NavigationService i used the BackStack property of the Frame
var x = Frame.BackStack.Cast<JournalEntry>().Select((page) => page).ToList();
Now it is just a matter of binding a listbox or whatever control you want to the Name property of the List above and in my case since i just needed to keep track of previous pages i added this code to the SelectionChanged event of the listbox bound to above List
void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int i = (sender as ListBox).Items.Count - (sender as ListBox).SelectedIndex;
for (; i > 0 && (sender as ListBox).SelectedIndex != -1; i--)
Frame.NavigationService.GoBack();
}

Get all controls of the current form at design-time

I have a question about design-time things:
I've made a component with an property "Links".
Those links are Controls. Now I want to make a UI-Dialog (for editing this property in the property grid).
How can I get all controls of the current form? I think the component has an connection to it, but where? I can't find anything.
Thanks :)
To get all of the controls of the current form then use the following code to get a collection of all of the controls on that form:
MyForm.Controls
See this MSDN help
Edit:
Perhaps these will help?
Design-time editor support for controls collection
http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/64df27e7-8502-42ac-8634-cf8a8937d922/
Adding design-time support for a nested container in a custom/usercontrol (Winforms)
This is quite untrivial to do, I don't know of any examples of .NET components that do this. You can get to the form at design time with the Site property but there are problems. What's hard to deal with is the user deleting controls, ones that you have already added to your controls collection. I don't know of any good trigger to keep your collection valid, beyond also having to use a custom designer for the form or user control.
There's a better mousetrap for this, you see it being used by the HelpProvider and ErrorProvider components for example. Note how they add properties to all other controls on the form. This is done by implementing the IExtenderProvider interface. There's an excellent example of this in the MSDN library article.
You can get IDesignerHost service at design-time. This service has a property called Container which has Components. Then for each component, get INestedContainer service and then get all components from that service.
This is how Document Outline window works. I've changed their method to use List<IComponent> as return value:
List<IComponent> GetSelectableComponents(IDesignerHost host)
{
var components = host.Container.Components;
var list = new List<IComponent>();
foreach (IComponent c in components)
list.Add(c);
for (var i = 0; i < list.Count; ++i)
{
var component1 = list[i];
if (component1.Site != null)
{
var service = (INestedContainer)component1.Site.GetService(
typeof(INestedContainer));
if (service != null && service.Components.Count > 0)
{
foreach (IComponent component2 in service.Components)
{
if (!list.Contains(component2))
list.Add(component2);
}
}
}
}
return list;
}
To filter the result to contain just controls, you can call result.TypeOf<Control>().
Not sure if this is what you want.
I "lost" a label control by accidentally removing it's text property.
After looking here at this discussion I finally realized that by accessing ANY control property at design time I could use the drop - down at the top of the properties window to locate the control name. Selecting the name revealed the location of the control on the form and exposed it's properties in the properties editor.

What is the best way to handle mutliple view/tab-ish GUI elements

I'm working on an application that presents the user with varied data, depending on the object being viewed. The objects are all of the same interface just with extended properties beyond once distinguished.
I'm looking for the "best" way to display a type-dependent control to the user. I would like to use tabs but I'm stuck with .NET 2.0 and from what I can gather the only way to hide/show tabs are to remove them and re-add them. That might be the best way but that leads to issues regarding blinking of the GUI components, keeping tabs on the active tab when reloading, etc.
I could make custom controls for each and either have them all loaded and hide/show when necessary (which I have done in the past on projects), or dispose and re-instantiate them...
To clarify best, I would say the closest balance between code elegance and program efficiency.
I have used and have had the best luck with loading them all and then showing/hiding the ones needed.
Disposing and re-instantiating everything always made things very messy.
In order to not have load time be horrible, you can instantiate them on first use. Something like:
IView LoadView(Type dependantType)
{
// get the view or create one
IView view = GetView(dependantType);
if (view == null)
{
view = InstantiateViewAndAddToForm(dependantType);
AddView(view);
}
//
// do some binding to your model or whatever here
//
// make the correct view visible
foreach (IView v in Views)
view.Visible = v == view;
}
Could you just create a panel for each object and have a dictionary associate the object type and the panel?
You could just tell the panel to bring to front if they are all the same size, or set all Panels.Visible to be false, and just set the one you need to be true.
I have used DockPanel Suite for applications that require multiple tabs.
It is an open source project, so you can actually modify the code if you wish.
The Suite has many functions, however, if you can just use the Tabs.

tabbed document interface in WPF using only on-board means?

I've seen two threads here about TDI & C#. Both of them didn't really answer the questions I have ...
Since TDIs are pretty much like a standard nowadays, I can hardly imagine, that I have to buy a special control (like AvalonDock or SandDock).
This must be possible with built in the tab-control(?) somehow! I don't need special features like dock- and draggable tabitems. Just open every form in a new tab. Thats it.
Like putting every forms content controls into user controls and by request (button, menu click ...) add a new tab and put the corresponding user control on it ... something like this.
How would you do it? This can't be THAT complicated (even for me) or am I missing something?!
thanks a lot!
Maybe Josh Smith's article on MVVM can give you an idea how to design such user interface. Example being built there is kinda tabbed document interface so you can use it as a starting block.
It's not that hard. It seems hard because there are a lot of different ways to do it.
Try this:
<TabControl x:Name="documentArea"/>
Handler for AddForm button:
private void AddFormClick(object sender, RoutedEventArgs e)
{
object form = GetNewForm();
documentArea.Items.Add(form);
}
That's it. You have to implement GetNewForm() in one of two ways. Have it return a user control that displays the form.
OR better yet, have it return your document that you want to display. Use a DataTemplate to select the controls to use for displaying this document. This method is going to be more complex to set up.

Categories

Resources