Windows phone visibility data binding in listbox itemtemplate?

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.

Up vote 1 down vote favorite share g+ share fb share tw.

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: 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! C# windows-phone-7 xaml link|improve this question asked Jan 26 at 23:02Fei Qu344 50% accept rate.

Sorry I didn't describe my problem clearly. What I want to do is if the logo is not empty, show the logo, hide the seller name. When the logo is empty, hide the logo, show the seller name.

However, in both cases, both logo and seller name are shown. – Fei Qu Jan 26 at 23:08.

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.

Thanks for your help, it works like a charm! I also posted another question related to windows phone here link I haven't got the solution yet. Can you help me have a look?

If you need more info, just let me know! Thanks! – Fei Qu Jan 27 at 6:58.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions