views:

26

answers:

1

I have a view with some controls and a viewbox. At the moment in the viewbox is a grid and a graphic at the bottom. The application reads a XML-file and refreshs the content of the grid and the graphic for every node in the XML-file.

Now the application not only have to show a grid with a graphic. Depending on the XML-node, the application should show a grid with a graphic like now or a grahpic and at the bottom 2 lines of text.

+1  A: 

You explained what your application is, but you didn't ask a question. Please state the question, and I can try to give you a better answer.

My best guess is "how do I do that? Do I need to write a custom control?" If that is what you are asking, you probably don't.

Usually you don't need a custom control to make a specialized view for a listbox, listview, or gridview. You can often use data templates, control templates or styles to achieve what you are looking for.

I am not sure if this is a good resource, but the XAML looks like it may be a good starting point for learning how to do control templates: http://ligao101.wordpress.com/2007/07/27/customizing-listview-in-wpf-part-i/

Simply googling for any of those terms ("ListView data template", etc) will probably get you some good information.

Edit:

From the comments, you are trying to support one of two types of data in the same space in the UI, depending on what is in your XML file:

  • Image Only
  • Image, plus two lines of text

One way to solve this would be to create a view model for your XML items, and bind the items to those view models:

public class XmlItemViewModel // Call this something more appropriate to your app
{
    public Visibility TextVisibility { get; set; }
    public string Text1 { get; set; }
    public string Text2 { get; set; }
    public Image Picture { get; set; }
}

If you already have a different class that has this data, keep it, and make the view model read properties off that class.

Bind the XAML TextBlock Visibility property to "{Binding TextVisibility}", and it should work. If you set the viewmodel property "Visibility.Collapsed", the text blocks will go away, and your ViewBox should shrink to fit only the image.

If you do this, you don't need a custom control, just a custom ViewModel class.

If it doesn't seem to collapse correctly, you could wrap your image and text blocks with a StackPanel or WrapPanel.

Merlyn Morgan-Graham
My problem is, I don't know what I have to search for. I explained the current functionality and the functionality which I need.I think to customize a ListView isn't what I searching for. Because the structure is diffrent.At the moment:<ViewBox><Grid>...</Grid><Image /></ViewBox>Now I want additional to this structure:<ViewBox><TextBox /><TextBox /><Image /></ViewBox>I need to change the content of the ViewBox at runtime.
elr
@elr: Do you need to support both? As in, one item in the ViewBox might display only a graphic, and the other might display a graphic plus two lines of text, and it supports both at the same time? Or do you just need the graphic + text version?
Merlyn Morgan-Graham
Yes i need to support both. The view (graphic+2lines or grid+graphic) is depending on the current node in the xml-file. Every 5 seconds the next node will be loaded. The xml-file contains both types of entries.
elr