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 7904195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:56:59+00:00 2026-06-03T09:56:59+00:00

This might be simple for you guys but am just starting in WPF, and

  • 0

This might be simple for you guys but am just starting in WPF, and always my mind thinks in terms of Winforms, and am wrong all the time.

Anyway here is my situation. I have label in my view like below:

UserControl

 <UserControl.Resources>

    <Converters:BooleanToVisibilityConverter x:Key="visibilityConverter"></Converters:BooleanToVisibilityConverter>

    <!-- Error Handling -->
    <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

    <Converters:ErrorConverter x:Key="errorConverter"/>
    <ControlTemplate x:Key="ErrorTemplate">
        <Border BorderBrush="Red" BorderThickness="2">
            <AdornedElementPlaceholder />
        </Border>
    </ControlTemplate>
    <Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource errorConverter}}"/>
            </Trigger>
        </Style.Triggers>
    </Style>
    <Style x:Key="comboBoxInError" TargetType="{x:Type ComboBox}">
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="true">
                <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource errorConverter}}"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</UserControl.Resources>

Label

<Label Name="IsImageValid"  Content="Image Created" Margin="0,7,-1,0" Style="{StaticResource LabelField}"
                    Grid.ColumnSpan="2" Grid.Row="15" Width="90" Height="28" Grid.RowSpan="2"
                    Grid.Column="1" IsEnabled="True" 
                    Visibility="{Binding IsImageValid,Converter={StaticResource BooleanToVisibilityConverter}}" />

I am trying to call the this label in my view model but not sure how.

I have t following method in the viewmodel, planning to use the label to display some message based on the condition like below.

  ViewModel

 public class MetadataViewModel : NotificationObject, IMetadataViewModel
{
    #region :: Properties ::

    private IEventAggregator eventAggregator;
    private IImageResizerService imageResizer;

    private string headerInfo;
    public string HeaderInfo
    {
        get
        {
            return headerInfo;
        }
        set
        {
            if (this.headerInfo != value)
            {
                this.headerInfo = value;
                this.RaisePropertyChanged(() => this.HeaderInfo);
            }
        }
    }

    public ICommand SaveCommand
    {
        get;
        private set;
    }

    public ICommand CloseCommand
    {
        get;
        private set;
    }

    public ICommand DeleteCommand
    {
        get;
        private set;
    }

    public ICommand SubmitCommand
    {
        get;
        private set;
    }

    public ICommand UnSubmitCommand
    {
        get;
        private set;
    }

    public ICommand LocationSearchCommand
    {
        get;
        private set;
    }

    public ICommand SubjectSearchCommand
    {
        get;
        private set;
    }

    public ICommand RemoveLocationCommand
    {
        get;
        private set;
    }

    public ICommand RemoveSubjectCommand
    {
        get;
        private set;
    }

    private StoryItem selectedStory;
    public StoryItem SelectedStory
    {
        get
        {
            return this.selectedStory;
        }
        set
        {
            if (this.selectedStory != value)
            {
                this.selectedStory = value;
                this.RaisePropertyChanged(() => this.SelectedStory);

                // raise dependencies
                this.RaisePropertyChanged(() => this.CanSave);
                this.RaisePropertyChanged(() => this.CanUnSubmit);
                this.RaisePropertyChanged(() => this.CanDelete);

            }
        }
    }


    public List<Program> ProgramList 
    { 
        get; 
        private set; 
    }

    public List<Genre> GenreList 
    { 
        get; 
        private set; 
    }

    public List<Copyright> CopyrightList 
    { 
        get; 
        private set; 
    }

    public bool CanSave
    {
        get
        {
            bool canSave = false;

            if (this.SelectedStory.IsLockAvailable)
            {
                if (!this.SelectedStory.Submitted)
                {
                    canSave = true;
                }
            }

            return canSave;
        }
    }

    public bool CanDelete
    {
        get
        {
            bool canDelete = false;

            if (this.SelectedStory.IsLockAvailable)
            {
                if (!this.SelectedStory.Submitted)
                {
                    canDelete = true;
                }
            }

            return canDelete;
        }
    }



    public bool CanUnSubmit
    {
        get
        {
            bool canUnSubmit = false;

            if (this.SelectedStory.IsLockAvailable)
            {
                if (this.SelectedStory.Submitted)
                {
                    canUnSubmit = true;
                }
            }

            return canUnSubmit;
        }
    }

    #endregion

    #region :: Contructor ::

    [ImportingConstructor]
    public MetadataViewModel(
            IMetadataController metadataController, 
            IGatewayService gateway, 
            INavigationService navigator,
            IImageResizerService imageResizer,
            IEventAggregator eventAggregator
        )
    {
        this.eventAggregator = eventAggregator;
        this.imageResizer = imageResizer;

        // populate drop-down lists
        this.ProgramList = gateway.GetPrograms(true);
        this.GenreList = gateway.GetGenres();
        this.CopyrightList = gateway.GetCopyrights();

        // add dummy values so the user can de-select
        this.ProgramList.Add(new Program());
        this.GenreList.Add(new Genre());
        this.CopyrightList.Add(new Copyright());

        // commands
        this.SaveCommand = metadataController.SaveCommand;
        this.CloseCommand = metadataController.CloseCommand;
        this.DeleteCommand = metadataController.DeleteCommand;
        this.SubmitCommand = metadataController.SubmitCommand;
        this.UnSubmitCommand = metadataController.UnSubmitCommand;



        this.LocationSearchCommand = new DelegateCommand<string>(this.LocationSearch);
        this.SubjectSearchCommand = new DelegateCommand<string>(this.SubjectSearch);
        this.RemoveLocationCommand = new DelegateCommand<Topic>(this.RemoveLocation);
        this.RemoveSubjectCommand = new DelegateCommand<Topic>(this.RemoveSubject);

        // events
        this.eventAggregator.GetEvent<StorySelectedEvent>().Subscribe(OnStorySelected, ThreadOption.UIThread);
        this.eventAggregator.GetEvent<AddLocationEvent>().Subscribe(OnAddLocation, ThreadOption.UIThread);
        this.eventAggregator.GetEvent<AddSubjectEvent>().Subscribe(OnAddSubject, ThreadOption.UIThread);
        this.eventAggregator.GetEvent<CommandCompletedEvent>().Subscribe(OnCommandCompleted, ThreadOption.UIThread);
        this.eventAggregator.GetEvent<ImageResizeCompletedEvent>().Subscribe(OnImageResizeCompleted, ThreadOption.UIThread);

        this.Initialize();
    }

    #endregion

    private void OnStorySelected(StoryItem selectedStory)
    {
        if (this.selectedStory != null)
        {
            this.Initialize();

            // override the initialized values
            this.SelectedStory = selectedStory;
            this.SelectedStory.HaveChanged = false;
            this.HeaderInfo = "Edit";
        }
    }

    public void OnAddLocation(Topic topic)
    {
        if (topic != null)
        {
            if (!this.SelectedStory.Locations.Contains(topic))
            {
                this.SelectedStory.Locations.Add(topic);
                this.RaisePropertyChanged(() => this.SelectedStory.Locations);
            }
        }
    }

    public void OnAddSubject(Topic topic)
    {
        if (topic != null)
        {
            if (!this.SelectedStory.Subjects.Contains(topic))
            {
                this.SelectedStory.Subjects.Add(topic);
                this.RaisePropertyChanged(() => this.SelectedStory.Subjects);
            }
        }
    }

    private void OnCommandCompleted(string commandType)
    {
        if (commandType == CommandTypes.MetadataEntry)
        {
            this.Initialize();
        }
    }

    private void OnImageResizeCompleted(bool isSuccessful)
    {
        IsImageValid = false;
        if (isSuccessful)
        {

            this.SelectedStory.KeyframeImages = true;
            IsImageValid = true;
        }
        else
        {
            this.SelectedStory.KeyframeImages = false;
            IsImageValid=false;
        }
    }

    private void Initialize()
    {
        this.SelectedStory = new StoryItem();
        this.HeaderInfo = "Create";
    }

    private void LocationSearch(object topicType)
    {
        this.eventAggregator.GetEvent<LocationSearchEvent>().Publish(null);
    }

    private void SubjectSearch(object topicType)
    {
        this.eventAggregator.GetEvent<SubjectSearchEvent>().Publish(null);
    }

    private void RemoveLocation(Topic selected)
    {
        if (selected != null)
        {
            // remove the primary too
            if (this.SelectedStory.PrimaryLocation != null)
            {
                if (string.Equals(this.SelectedStory.PrimaryLocation.FullName, selected.FullName, StringComparison.InvariantCultureIgnoreCase))
                {
                    this.SelectedStory.PrimaryLocation = new Topic();
                }
            }

            bool isSuccessful = this.SelectedStory.Locations.Remove(selected);
            if (isSuccessful)
            {
                this.RaisePropertyChanged(() => this.SelectedStory.Locations);
            }
        }
    }

    private void RemoveSubject(Topic selected)
    {
        if (selected != null)
        {
            // remove the primary too
            if (this.SelectedStory.PrimarySubject != null)
            {
                if (string.Equals(this.SelectedStory.PrimarySubject.FullName, selected.FullName, StringComparison.InvariantCultureIgnoreCase))
                {
                    this.SelectedStory.PrimarySubject = new Topic();
                }
            }

            bool isSuccessful = this.SelectedStory.Subjects.Remove(selected);
            if (isSuccessful)
            {
                this.RaisePropertyChanged(() => this.SelectedStory.Subjects);
            }
        }
    }
}

        private booly _isImageValid;

        public bool IsImageValid
        {
        get
        { 
            return _isImageValid;
        }
        set
        {
            _isImageValid = value;
            this.RaisePropertyChanged(() => this.IsImageValid);
        }
    }
}

Honestly i don’t know how view will understand the binding.

  • 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-06-03T09:57:00+00:00Added an answer on June 3, 2026 at 9:57 am

    A standard approach is to have a boolean property like “IsImageValid” in your ViewModel…Then in your XAML, bind the Visibility property of your label to that property, with a BooleanToVisibilityConverter http://msdn.microsoft.com/en-us/library/system.windows.controls.booleantovisibilityconverter.aspx

    <UserControl.Resources>
      <BooleanToVisibilityConverter
             x:Key="BooleanToVisibilityConverter" />
    </UserControl.Resources>
    Then use it in one or more bindings like this:
    
    <Label Visibility="{Binding IsImageValid, 
           Converter={StaticResource BooleanToVisibilityConverter}}" 
       ......... />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a simple question but I'm just picking this up so please
This might seem ridiculously simple, but I've been getting all kinds of error depending
I dunno guys, this is a really weird one, but I might just be
This might be simple for seasoned java developers but I just cant seem to
This might be simple but I am new to Oracle. I am using Oracle
Ok, this might sound simple but am not sure what to do. I am
This might be a simple question but I've searched and searched and can't find
This might be a simple question, but i can't seem to grasp it. I
This might be a simple answer, but I am having some issues writing this
This might be a simple question, but I'm fairly new to PHP and am

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.