Custom value Converter

Source: Internet
Author: User

When we write pages on the front-end, sometimes the data provided to us by the backend is not ready for use. We need to convert the data for use. Therefore, we need to create a front-end Data Conversion Tool class

 Using  System;  Using  System. Collections. Generic;  Using  System. LINQ;  Using  System. text;  Using  System. Threading. tasks;  Using  Windows. UI. XAML;  Using  Windows. UI. XAML. Data; Namespace  Gridexp {  Public   Class  Boolvisibilityconverter: ivalueconverter {  Public   Object Convert ( Object Value, type targettype, Object Parameter, String  Language ){  //  Value is the data in the model, and the returned value is the data in the UI after conversion.              Bool B = ( Bool  ) Value;  Return B? Visibility. Visible: visibility. collapsed ;}  Public   Object Convertback ( Object Value, type targettype, Object Parameter, String  Language ){  //  Value is the value of the data type in the UI into the model (twoway binding) Visibility v =(Visibility) value;  Return V = Visibility. visible ;}}} 

REFERENCE The namespace of the class in the first tag.

 <  Common: layoutawarepage  X: Name  = "Pageroot"  X: Class  = "Gridexp. groupeditemspage"  Datacontext  ="  {Binding defaviewviewmodel, relativesource = {relativesource self }}  " Xmlns  = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"  Xmlns: x  = "Http://schemas.microsoft.com/winfx/2006/xaml"  Xmlns: Local= "Using: gridexp"  Xmlns: Data  = "Using: gridexp. Data"  Xmlns: Common  = "Using: gridexp. Common"  Xmlns: d  = "Http://schemas.microsoft.com/expression/blend/2008"  Xmlns: MC = "Http://schemas.openxmlformats.org/markup-compatibility/2006"  MC: ignorable  = "D"  > 

Set another resource, which is equivalent to a new object in this page.

<Page. Resources><! --The set of group items displayed on this page is bound to the subset of the full item list because the items in the virtualization group cannot be--><Local: boolvisibilityconverterX: Key= "Boovisconverter"> </Local: boolvisibilityconverter>

Finally, use

<ImageSource= "Images/w_mengchong.jpg"Visibility="{Binding isunmem, converter = {staticresource boovisconverter }}"Width= "50"Height= "50"> </Image>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.