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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:25:56+00:00 2026-05-28T17:25:56+00:00

I have a problem with control visibility in listbox itemtemplate. Following is my code

  • 0

I have a problem with control visibility in listbox itemtemplate. Following is my code to bind data to Visibility property of imagetools:AnimatedImage and Textblock in xaml:

<ListBox x:Name="listSellers" ItemsSource="{Binding TagList}" SelectionChanged="listSellers_SelectionChanged" ScrollViewer.VerticalScrollBarVisibility="Disabled">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <Grid Margin="0,12,0,12" Height="132">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" MinWidth="107"/>
                                                    <ColumnDefinition/>
                                                </Grid.ColumnDefinitions>
                                                <Border Grid.Column="0" Margin="0,0,-2,8">
                                                    <Grid>
                                                        <imagetools:AnimatedImage Source="{Binding Seller.Logo, Converter={StaticResource ImageConverter}}" Stretch="Uniform" Width="240" Template="{StaticResource AnimatedImageControlTemplate1}" Visibility="{Binding LogoVisibility}"/>
                                                        <TextBlock x:Name="sellerNameTxtBlock" TextWrapping="Wrap" Text="{Binding Seller.Name}" FontSize="24" FontFamily="Segoe WP" Margin="10,0,0,0" Foreground="#FF354F59" Height="41" Visibility="{Binding Path=SellerNameVisibility}"/>
                                                    </Grid>
                                                </Border>
                                                <StackPanel Grid.Column="1" Orientation="Vertical">
                                                    <!--<TextBlock TextWrapping="Wrap" Text="{Binding Seller.Name}" FontSize="24" FontFamily="Segoe WP" Margin="10,0,0,0" Foreground="#FF354F59" Height="41"/>-->
                                                    <!--<TextBlock TextWrapping="Wrap" Text="amazon.com" FontSize="16" FontFamily="Segoe WP" Margin="10,0,0,0" Foreground="#FF157CCC" Height="35"/>-->
                                                    <TextBlock TextWrapping="Wrap" Text="{Binding TotalPrice}" FontSize="21.333" FontFamily="Segoe WP Semibold" Margin="10,0,0,0" Foreground="#cc4225"/>
                                                    <TextBlock FontSize="{StaticResource PhoneFontSizeSmall}" Text="{Binding Price}" Margin="10,0,0,0" Foreground="#FF354F59"/>
                                                    <TextBlock FontSize="{StaticResource PhoneFontSizeSmall}" Text="{Binding Tax}" Margin="10,0,0,0" Foreground="#FF354F59"/>
                                                    <TextBlock FontSize="{StaticResource PhoneFontSizeSmall}" Text="{Binding Shipping}" Margin="10,0,0,0" Foreground="#FF354F59"/>
                                                </StackPanel>
                                            </Grid>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
</ListBox>

Following is the declaration of the property in view model:

public Visibility LogoVisibility
        {
            get { return (Visibility)GetValue(LogoVisibilityProperty); }
            set { SetValue(LogoVisibilityProperty, value); }
        }

        // Using a DependencyProperty as the backing store for LogoVisibility.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty LogoVisibilityProperty =
            DependencyProperty.Register("LogoVisibility", typeof(Visibility), typeof(ProductDetailViewModel), new PropertyMetadata(Visibility.Collapsed));

        public Visibility  SellerNameVisibility
        {
            get { return (Visibility )GetValue(SellerNameVisibilityProperty); }
            set { SetValue(SellerNameVisibilityProperty, value); }
        }

        // Using a DependencyProperty as the backing store for SellerNameVisibility.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty SellerNameVisibilityProperty =
            DependencyProperty.Register("SellerNameVisibility", typeof(Visibility), typeof(ProductDetailViewModel), new PropertyMetadata(Visibility.Collapsed));

Following is where I set Visibility in view model:

foreach (Tag tag in tagArray)
                {
                    if (tag.Seller.Logo.Equals(""))
                    {
                        tag.Seller.Logo = "Images/NoImageFound.png";
                        LogoVisibility = Visibility.Collapsed;
                        SellerNameVisibility = Visibility.Visible;
                    }
                    else
                    {
                        LogoVisibility = Visibility.Visible;
                        SellerNameVisibility = Visibility.Collapsed;
                    }
                    tag.Price = "Base: " + tag.Price;
                    if (tag.Tax == null)
                    {
                        tag.Tax = "Tax: N/A";
                    }
                    else
                    {
                        tag.Tax = "Tax: " + tag.Tax;
                    }
                    if (tag.Shipping == null)
                    {
                        tag.Shipping = "Ship: N/A";
                    }
                    else
                    {
                        tag.Shipping = "Ship: " + tag.Shipping;
                    }
                    tempTagList.Add(tag);
                }
                TagList = tempTagList;
            }

And here’s where I set the datacontext in code behind:

protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            _productDetailViewModel = new ProductDetailViewModel();
            DataContext = _productDetailViewModel;
            string productTitleId = "";
            if (NavigationContext.QueryString.TryGetValue("productTitleId", out productTitleId))
            {
                _productTitleId = productTitleId;
                _productDetailViewModel.getProductDetailFromServer(_productTitleId, "");
            }
        }

I also do some other data bindings in these files, all of them work. Only this Visibility binding fails. Really don’t know why. =( Any ideas? Thanks!!!

  • 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-28T17:25:57+00:00Added an answer on May 28, 2026 at 5:25 pm

    Looks like your ListBox ItemsSource is bound to a collection of “Tag” objects. This means that each ListBoxItem would be bound to a “Tag” object. So, the DataTemplate you are creating has a DataContext equal to one Tag object. I do not see that LogoVisibility is on the Tag object. It looks like it is on the object that holds a reference to the tag list. Going this route, you would want the LogoVisibility and NameVisibility on the Tag object itself.

    What I would suggest is to not put that logic into your model object (Tag) and instead have a ValueConverter to handle this logic.

        public class EmptyToVisibilityConverter : IValueConverter
    {
        #region IValueConverter Members
    
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return Visibility.Collapsed;
    
            string val = value.ToString();
    
            return string.IsNullOrWhiteSpace(val) ? Visibility.Collapsed : Visibility.Visible;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    
        #endregion
    }
    

    Then change your Visibility bindings to:

        <Grid DataContext="{Binding Seller}">
            <imagetools:AnimatedImage Source="{Binding Logo, Converter={StaticResource ImageConverter}}" 
                                  Stretch="Uniform" Width="240" 
                                  Template="{StaticResource AnimatedImageControlTemplate1}" 
                                  Visibility="{Binding Logo, Converter={StaticResource EmptyToVis}}"/>
            <TextBlock x:Name="sellerNameTxtBlock" TextWrapping="Wrap" Text="{Binding Name}" FontSize="24" 
                   FontFamily="Segoe WP" Margin="10,0,0,0" Foreground="#FF354F59" Height="41" 
                   Visibility="{Binding Name, Converter={StaticResource EmptyToVis}}"/>
        </Grid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have the following PHP code to control the visibility of a block:
I have a problem with a data-bound DataGrid control, in that despite each column
I have a problem regarding getting the path of a user control. The scenario
I have a problem styling/templating an AccordionItem in the accordion control from the silverlight
I have a problem that i cant solve :( I have a user control
Problem I have a custom tab control using Chrome-shaped tabs that binds to a
I have encountered a rather nasty problem with the DataGridView control (Windows.Forms, .NET Framework
Hi The problem am having is that I have multiple TreeView control and each
I have an Accordion control to which I have added a datagrid. The problem
Atleast defining my problem is simple... I have a Input control (Text) and a

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.