Click here to Skip to main content
15,881,757 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Installed Silverlight 3 Tools, Getting Exception Pin
Abhinav S15-Apr-10 18:22
Abhinav S15-Apr-10 18:22 
GeneralRe: Installed Silverlight 3 Tools, Getting Exception Pin
#realJSOP16-Apr-10 1:30
mve#realJSOP16-Apr-10 1:30 
QuestionSilverlight 3 MediaElement - Mac Progressive Download problem with playing full movies Pin
JustinSays14-Apr-10 1:21
JustinSays14-Apr-10 1:21 
QuestionHow to display another user control Pin
#realJSOP13-Apr-10 8:57
mve#realJSOP13-Apr-10 8:57 
AnswerRe: How to display another user control [modified] Pin
Abhinav S13-Apr-10 18:13
Abhinav S13-Apr-10 18:13 
AnswerRe: How to display another user control Pin
Frank W. Wu12-Oct-10 4:52
Frank W. Wu12-Oct-10 4:52 
QuestionTreeViewItem and opening a modal dialog from the contextmenu (Properties) [modified] Pin
Diving Flo13-Apr-10 3:30
Diving Flo13-Apr-10 3:30 
GeneralRe: TreeViewItem and opening a modal dialog from the contextmenu (Properties) Pin
Diving Flo13-Apr-10 20:28
Diving Flo13-Apr-10 20:28 
OK, I try to give more information. Maybe the last post was misleading. I have the following attached property (shortened):

public class DialogBehavior
   {
      public static DependencyProperty DisplayModalProperty = DependencyProperty.RegisterAttached("DisplayModalProperty",
                    typeof(Boolean),
                    typeof(DialogBehavior),
                    new UIPropertyMetadata(false, AttachToDataContextChanged));

      public static void SetDisplayModal(DependencyObject target, Boolean value)
      {
         target.SetValue(DialogBehavior.DisplayModalProperty, value);
      }

      public static Boolean GetDisplayModal(DependencyObject target)
      {
         return (Boolean)target.GetValue(DisplayModalProperty);
      }

      private static void AttachToDataContextChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
      {
         FrameworkElement element = target as FrameworkElement;

            element.DataContextChanged += (a, b) =>
            {
               var dialog = new Dialog();
               dialog.DataContext = b.NewValue;
               dialog.Owner = Application.Current.MainWindow;

               if (GetDisplayModal(target))
               {
                  dialog.ShowDialog();
               }
               else
               {
                  dialog.Show();
               }
            };
         }
      }
   }


When this is attached a handler for the DataContextChanged-event is registered. The handler opens a dialog when the DataContext changed.

Now I need to nest a FrameworkElement which is holding the DataContext into a TreeViewItem. What I did up to now is the following:

<HierarchicalDataTemplate DataType="{x:Type ViewModels:TreeNodeViewModel}" 
                             ItemsSource="{Binding Children}">
    <StackPanel>
        <FrameworkElement DataContext="{Binding Path=ModalDialogViewModel}">
            <behaviour:DialogBehavior.DisplayModal>True</behaviour:DialogBehavior.DisplayModal>
        </FrameworkElement>
        <TextBlock Text="{Binding DisplayName}" />
    </StackPanel>
</HierarchicalDataTemplate>


But, as soon as new TreeViewItems are added, I get a first chance exception of type 'System.NullReferenceException' occurred in PresentationFramework.dll. The problem must be in my DialogBehavior. Because as soon as I take this out, the code works.

So what is my mistake?

I appreciate any ideas!

Florian
AnswerRe: TreeViewItem and opening a modal dialog from the contextmenu (Properties) Pin
Diving Flo14-Apr-10 23:23
Diving Flo14-Apr-10 23:23 
QuestionOpen window in New browser window Pin
Tripathi Swati13-Apr-10 0:38
Tripathi Swati13-Apr-10 0:38 
AnswerRe: Open window in New browser window Pin
Abhinav S13-Apr-10 5:52
Abhinav S13-Apr-10 5:52 
GeneralRe: Open window in New browser window Pin
Tripathi Swati15-Apr-10 21:00
Tripathi Swati15-Apr-10 21:00 
QuestionPhilosophical question on MVVM lookups and practical one on entity fields.... Pin
RichardGrimmer12-Apr-10 23:57
RichardGrimmer12-Apr-10 23:57 
AnswerRe: Philosophical question on MVVM lookups and practical one on entity fields.... Pin
Abhinav S13-Apr-10 5:51
Abhinav S13-Apr-10 5:51 
GeneralRe: Philosophical question on MVVM lookups and practical one on entity fields.... Pin
RichardGrimmer13-Apr-10 9:05
RichardGrimmer13-Apr-10 9:05 
GeneralRe: Philosophical question on MVVM lookups and practical one on entity fields.... Pin
Abhinav S13-Apr-10 18:31
Abhinav S13-Apr-10 18:31 
GeneralRe: Philosophical question on MVVM lookups and practical one on entity fields.... Pin
RichardGrimmer13-Apr-10 21:30
RichardGrimmer13-Apr-10 21:30 
QuestionSelecting an item as per value in combobox in wpf Pin
dashingsidds12-Apr-10 22:50
dashingsidds12-Apr-10 22:50 
AnswerRe: Selecting an item as per value in combobox in wpf Pin
Arun Jacob12-Apr-10 22:58
Arun Jacob12-Apr-10 22:58 
GeneralRe: Selecting an item as per value in combobox in wpf [modified] Pin
dashingsidds12-Apr-10 23:26
dashingsidds12-Apr-10 23:26 
AnswerRe: Selecting an item as per value in combobox in wpf Pin
Arun Jacob12-Apr-10 23:30
Arun Jacob12-Apr-10 23:30 
GeneralRe: Selecting an item as per value in combobox in wpf Pin
dashingsidds12-Apr-10 23:41
dashingsidds12-Apr-10 23:41 
GeneralRe: Selecting an item as per value in combobox in wpf Pin
Arun Jacob12-Apr-10 23:47
Arun Jacob12-Apr-10 23:47 
AnswerRe: Selecting an item as per value in combobox in wpf Pin
Sunil Scaria12-Apr-10 23:15
Sunil Scaria12-Apr-10 23:15 
GeneralRe: Selecting an item as per value in combobox in wpf Pin
dashingsidds12-Apr-10 23:28
dashingsidds12-Apr-10 23:28 

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.