Click here to Skip to main content
15,916,030 members
Home / Discussions / C#
   

C#

 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
indian1436-Aug-18 7:32
indian1436-Aug-18 7:32 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
Richard Deeming6-Aug-18 9:16
mveRichard Deeming6-Aug-18 9:16 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
indian1436-Aug-18 10:12
indian1436-Aug-18 10:12 
GeneralRe: Want to change the Validation attribute at runtime ASP.Net MVC Pin
Richard Deeming7-Aug-18 1:56
mveRichard Deeming7-Aug-18 1:56 
QuestionWhen inputting data form main one other always on form main ? Pin
Member 24584672-Aug-18 21:29
Member 24584672-Aug-18 21:29 
AnswerRe: When inputting data form main one other always on form main ? Pin
Richard MacCutchan2-Aug-18 21:40
mveRichard MacCutchan2-Aug-18 21:40 
AnswerRe: When inputting data form main one other always on form main ? Pin
OriginalGriff2-Aug-18 21:45
mveOriginalGriff2-Aug-18 21:45 
GeneralRe: When inputting data form main one other always on form main ? Pin
Member 24584675-Aug-18 16:42
Member 24584675-Aug-18 16:42 
GeneralRe: When inputting data form main one other always on form main ? Pin
OriginalGriff5-Aug-18 19:35
mveOriginalGriff5-Aug-18 19:35 
AnswerRe: When inputting data form main one other always on form main ? Pin
BillWoodruff3-Aug-18 2:17
professionalBillWoodruff3-Aug-18 2:17 
QuestionC# Pin
Jeremiah Okoduwa2-Aug-18 0:51
Jeremiah Okoduwa2-Aug-18 0:51 
AnswerRe: C# Pin
Daniel Pfeffer2-Aug-18 1:12
professionalDaniel Pfeffer2-Aug-18 1:12 
AnswerRe: C# Pin
Nathan Minier2-Aug-18 1:14
professionalNathan Minier2-Aug-18 1:14 
AnswerRe: C# Pin
OriginalGriff2-Aug-18 1:19
mveOriginalGriff2-Aug-18 1:19 
AnswerRe: C# Pin
Richard MacCutchan2-Aug-18 1:33
mveRichard MacCutchan2-Aug-18 1:33 
AnswerRe: C# Pin
BillWoodruff3-Aug-18 2:23
professionalBillWoodruff3-Aug-18 2:23 
QuestionCombining TreeView and Canvas in WPF ( MVVM ) Pin
Kenneth Haugland30-Jul-18 21:50
mvaKenneth Haugland30-Jul-18 21:50 
AnswerRe: Combining TreeView and Canvas in WPF ( MVVM ) Pin
Pete O'Hanlon30-Jul-18 23:47
mvePete O'Hanlon30-Jul-18 23:47 
GeneralRe: Combining TreeView and Canvas in WPF ( MVVM ) Pin
Kenneth Haugland31-Jul-18 2:05
mvaKenneth Haugland31-Jul-18 2:05 
AnswerRe: Combining TreeView and Canvas in WPF ( MVVM ) Pin
Gerry Schmitz31-Jul-18 13:08
mveGerry Schmitz31-Jul-18 13:08 
GeneralRe: Combining TreeView and Canvas in WPF ( MVVM ) Pin
Kenneth Haugland31-Jul-18 21:26
mvaKenneth Haugland31-Jul-18 21:26 
GeneralRe: Combining TreeView and Canvas in WPF ( MVVM ) Pin
Gerry Schmitz2-Aug-18 7:33
mveGerry Schmitz2-Aug-18 7:33 
GeneralRe: Combining TreeView and Canvas in WPF ( MVVM ) Pin
Kenneth Haugland2-Aug-18 23:56
mvaKenneth Haugland2-Aug-18 23:56 
Not initially no. But as soon as I had the treeview up and running with binding:
HTML
<TreeView x:Name="tree">
    <TreeView.Resources>
        <HierarchicalDataTemplate DataType="{x:Type local:HierarchyBase}" ItemsSource="{Binding Children}" >
            <TextBox Text="{Binding Name}"/>
        </HierarchicalDataTemplate>
    </TreeView.Resources>
</TreeView>

This was very neat, but now how to bind the canvas to the code behind? I thought this was very messy.
C#
public abstract class HierarchyBase : INotifyPropertyChanged
   {
       public HierarchyBase()
       {
           Delete = new RelayCommand( CanDelete, DeleteThis);
           children.CollectionChanged +=ItemChildren_CollectionChanged;
       }

       public Canvas myCanvas;
       private HierarchyBase _parent;

       private void ItemChildren_CollectionChanged(object sender,NotifyCollectionChangedEventArgs e)
       {
           //different kind of changes that may have occurred in collection
           if (e.Action == NotifyCollectionChangedAction.Add)
           {
               foreach (var item in e.NewItems)
               {
                   ((HierarchyBase)item)._parent = this;
                   ((HierarchyBase)item).myCanvas = this.myCanvas;
               }
               //((List<object>)e.NewItems).ForEach(i => ((HierarchyBase)i)._parent = this); // foreach (e.NewItems)(i => i;)

           }
           if (e.Action == NotifyCollectionChangedAction.Replace)
           {
               //your code
           }
           if (e.Action == NotifyCollectionChangedAction.Remove)
           {
               foreach (var item   in e.OldItems)
               {
                   ((HierarchyBase)item)._parent = null;
                   ((HierarchyBase)item).myCanvas = null;
               }
           }
           if (e.Action == NotifyCollectionChangedAction.Move)
           {
               //your code
           }
       }

       private ObservableCollection<HierarchyBase> children = new ObservableCollection<HierarchyBase>();


       public ObservableCollection<HierarchyBase> Children
       {
           get { return children; }
           set { children = value; }
       }

       public ICommand Delete { get; set; }

       private bool CanDelete(object obj)
       {
           return IsEnabled;
       }

       private void DeleteThis(object obj)
       {
           this._parent.Children.Remove(this);
       }

       public string Name { get; set; }

       private bool pIsEnabled = true;
       public bool IsEnabled
       {
           get { return pIsEnabled; }
           set { pIsEnabled = value;
               OnPropertyChanged();
           }
       }

       private bool pIsVisible = true;

       public bool IsVisible
       {
           get { return pIsVisible; }
           set {
               pIsVisible = value;
               OnPropertyChanged();
           }
       }

       private void StateUpdated()
       {
           if (this is IDrawing)
           {
               ((IDrawing)this).Redraw(IsVisible);
           }

           foreach (HierarchyBase child in Children)
           {
               if (!this.IsEnabled || !this.IsVisible)
               {
                   child.IsVisible = false;
               }
           }
       }

       public event PropertyChangedEventHandler PropertyChanged;

       private void OnPropertyChanged([CallerMemberName]string caller = "")
       {
           // make sure only to call this if the value actually changes

           var handler = PropertyChanged;
           if (handler != null)
           {
               handler(this, new PropertyChangedEventArgs(caller));
               StateUpdated();
           }
       }
   }


Any ideas on how to bind the canvas to the code behind in XAML? All I came up with was to bind the canvas manually to the first HierarchicalBase item when I loaded the program. I just thought I was messy and ugly.
GeneralRe: Combining TreeView and Canvas in WPF ( MVVM ) Pin
Gerry Schmitz3-Aug-18 7:54
mveGerry Schmitz3-Aug-18 7:54 
QuestionWhy does the DataTable get strings do not exceed 255 characters ? Pin
Member 245846729-Jul-18 18:55
Member 245846729-Jul-18 18:55 

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.