Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7592827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:00:15+00:00 2026-05-30T21:00:15+00:00

i create a dependency property to close a view from view model, dependencyProperty: public

  • 0

i create a dependency property to close a view from view model,

dependencyProperty:

  public static class WindowBehaviors 
  {      
     public static readonly DependencyProperty IsOpenProperty =
              DependencyProperty.RegisterAttached("IsOpen"
             , typeof(bool),
             typeof(WindowBehaviors),
             new UIPropertyMetadata(false, IsOpenChanged));

    private static void IsOpenChanged(DependencyObject   obj,DependencyPropertyChangedEventArgs args)
    {
        Window window = Window.GetWindow(obj);

        if (window != null && ((bool)args.NewValue))
            window.Close();
    }


    public static bool GetIsOpen(Window target)
    {
        return (bool)target.GetValue(IsOpenProperty);
    }

    public static void SetIsOpen(Window target, bool value)
    {
        target.SetValue(IsOpenProperty, value);
    }
}

and use it in my xaml like this:

<window
...
Command:WindowBehaviors.IsOpen="True">

it work’s fine,but when i want to bind it to a property in viewModel,it dosen’t work,and i guess,it dosen’t work because i define the resource later in xaml.

in xaml:

 <Window.Resources>
     <VVM:myVieModel x:Key="myVieModel"/>
 </Window.Resources>

and i don’t know what should i do,where should i put this:

Command:WindowBehaviors.IsOpen="{binding Isopen}"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:00:16+00:00Added an answer on May 30, 2026 at 9:00 pm

    Thanks for your helps,i fixed it and here is my solution,
    i used to use MVVMToolkit but now i’m useing MVVMlight and as you know in MVVMLight,we just define Application Resources Once in App.xaml.so we can bind all the window’s properties simply,hope this can help some people who has the same problem!!

    app.xaml

      <Application.Resources>
        <!--Global View Model Locator-->
        <vm:ViewModelLocator x:Key="Locator"
                             d:IsDataSource="True" />
      </Application.Resources>
    

    and in the window(view)

    DataContext="{Binding DefaultSpecItemVM, Source={StaticResource Locator}}"
    

    and it works perfect.:D

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I like to create a UserControl with own Header Property. public partial class SomeClass:
I wonder, how to create this binding, since Line.X2 IS NOT dependency property! :(
I have a question regarding dependency injection. say i want to create a class
I need to create a dependency property on a custom control. The problem is
I tried to create a user control as: public partial class MyTextBlock : UserControl
Is it possible to create a Dependency Property for multiple controls without resorting to
I have an Id dependency property declared: public long Id { get { return
How can I create a custom read-only Boolean dependency property that returns And operation
I want to create a DependencyProperty with 2 options (Left and Right) similar to
How do you create a read-only dependancy property? What are the best-practices for doing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.