Click here to Skip to main content
15,886,105 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: InvalidateMeasure doesn't trigger MeasureOverride call? Pin
SledgeHammer0122-Aug-12 13:40
SledgeHammer0122-Aug-12 13:40 
GeneralRe: InvalidateMeasure doesn't trigger MeasureOverride call? Pin
Pete O'Hanlon22-Aug-12 23:53
mvePete O'Hanlon22-Aug-12 23:53 
GeneralRe: InvalidateMeasure doesn't trigger MeasureOverride call? Pin
SledgeHammer0123-Aug-12 5:08
SledgeHammer0123-Aug-12 5:08 
GeneralRe: InvalidateMeasure doesn't trigger MeasureOverride call? Pin
Pete O'Hanlon23-Aug-12 5:15
mvePete O'Hanlon23-Aug-12 5:15 
GeneralRe: InvalidateMeasure doesn't trigger MeasureOverride call? Pin
SledgeHammer0123-Aug-12 8:34
SledgeHammer0123-Aug-12 8:34 
GeneralRe: InvalidateMeasure doesn't trigger MeasureOverride call? Pin
SledgeHammer0123-Aug-12 13:03
SledgeHammer0123-Aug-12 13:03 
QuestionWPF Problem With WrapPanel In ListBox.ItemsPanel [UPDATED] Pin
Kevin Marois20-Aug-12 14:33
professionalKevin Marois20-Aug-12 14:33 
QuestionSwitch WPF UI at runtime Pin
Ed Hill _5_17-Aug-12 0:43
Ed Hill _5_17-Aug-12 0:43 
I have a set of data that can be defined by the user, this will consist of item types i provide to them, for example (Text/Date/Decimal/Address/Lookup/Group). A group allows them to put related data together, groups can be nested as deep as the user requires. Think Composite pattern. As every user is able to create their own structure how it is best displayed will also vary from user to user.

I would like to be able to provide a mechanism that allows the user to select how they want their data displayed. To do this i have created a ResourceDictionary for each way of displaying the data but i've struggled to find a good way to implement switching between display methods. I have looked into switching the ResourceDictionary in code but could not find a good way to implement this. I've also thought about implementing a DataTemplateSelector and again struggled to get this working.

I tried creating empty interfaces (IShowAsTree, IShowAsTabs, IShowAsGroupBoxes), implementing them all in my view that holds the data, and casting when i return the property they are bound to.

public interface IBaseView{}
public interface IShowAsTree:IBaseView{}
public interface IShowAsTabs:IBaseView{}
public interface IShowAsGroupBoxes:IBaseView{}

public class DataCollection:BaseVM, IShowAsTree, IShowAsTabs, IShowAsGroupBoxes
{
    //extended data class
}

public class ExtenededDataView:BaseVM
{
    public String[] ViewAsOptions{get{return new[] {"Tree","Tabs","GroupBoxes"}}

    private String _viewAs;
    public String ViewAs
    {
        get {return _viewAs;}
        set
        {
            _viewAs = value;
            OnPropertyChanged(()=>View);
        }
    }
    private DataCollection _view;
    public IBaseView View
    {
        get
        {
            switch(ViewAs)
            {
                case "Tree":
                return _view as IShowTabs;
                break;
                //...
            }
        }
    }
}


This failed, should have known but DataTemplating appears to only work on classes not interfaces. This is when i decided on quite a hack for a solution, replace the interfaces with classes, and put a property in the parent class that holds the DataCollection. This works but feels wrong, so if any one can advice me of a better solution, or an area to research more it would be appreciated. Thanks to anyone who read this far, code was typed in so may well contain the odd error, but hopefully its enough to describe the problem.

Working Hack:
public class SwitchMyUI
    {
        public DataCollection Details { get; set; }

        public SwitchMyUI(DataCollection details)
        {
            Details = details;
        }

        public SwitchMyUI(SwitchMyUI copyFrom)
        {
            Details = copyFrom.Details;
        }
    }

    public class ShowTabs : SwitchMyUI
    {
        public ShowTabs(SwitchMyUI copyFrom) : base(copyFrom)
        {
        }
    }

    public class ShowTree : SwitchMyUI
    {
        public ShowTree(SwitchMyUI copyFrom) : base(copyFrom)
        {
        }
    }


Edit: Included WPF in the title
AnswerRe: Switch WPF UI at runtime Pin
Kenneth Haugland18-Aug-12 12:54
mvaKenneth Haugland18-Aug-12 12:54 
GeneralRe: Switch WPF UI at runtime Pin
Ed Hill _5_18-Aug-12 23:45
Ed Hill _5_18-Aug-12 23:45 
AnswerRe: Switch WPF UI at runtime Pin
Abhinav S18-Aug-12 18:31
Abhinav S18-Aug-12 18:31 
GeneralRe: Switch WPF UI at runtime Pin
Ed Hill _5_19-Aug-12 21:57
Ed Hill _5_19-Aug-12 21:57 
AnswerRe: Switch WPF UI at runtime Pin
Pete O'Hanlon20-Aug-12 0:48
mvePete O'Hanlon20-Aug-12 0:48 
QuestionWPF ListBox Question Pin
Kevin Marois15-Aug-12 15:22
professionalKevin Marois15-Aug-12 15:22 
AnswerRe: WPF ListBox Question Pin
Ed Hill _5_15-Aug-12 22:07
Ed Hill _5_15-Aug-12 22:07 
GeneralRe: WPF ListBox Question Pin
Kevin Marois16-Aug-12 6:10
professionalKevin Marois16-Aug-12 6:10 
QuestionComboBox Dropdown Problem Pin
#realJSOP15-Aug-12 4:49
mve#realJSOP15-Aug-12 4:49 
AnswerRe: ComboBox Dropdown Problem Pin
Pete O'Hanlon15-Aug-12 5:12
mvePete O'Hanlon15-Aug-12 5:12 
GeneralRe: ComboBox Dropdown Problem Pin
#realJSOP15-Aug-12 5:13
mve#realJSOP15-Aug-12 5:13 
GeneralRe: ComboBox Dropdown Problem Pin
#realJSOP15-Aug-12 5:17
mve#realJSOP15-Aug-12 5:17 
GeneralRe: ComboBox Dropdown Problem Pin
#realJSOP15-Aug-12 6:45
mve#realJSOP15-Aug-12 6:45 
AnswerRe: ComboBox Dropdown Problem Pin
Pete O'Hanlon15-Aug-12 22:59
mvePete O'Hanlon15-Aug-12 22:59 
GeneralRe: ComboBox Dropdown Problem Pin
#realJSOP16-Aug-12 1:27
mve#realJSOP16-Aug-12 1:27 
GeneralRe: ComboBox Dropdown Problem Pin
Pete O'Hanlon16-Aug-12 1:46
mvePete O'Hanlon16-Aug-12 1:46 
GeneralRe: ComboBox Dropdown Problem Pin
#realJSOP17-Aug-12 4:05
mve#realJSOP17-Aug-12 4:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.