문제

I have a DataModel and a ViewModel working successfully together with my xaml view. In the view I use databindings.

In my DataModel I have some properties like Distance declared as int.

When displaying the values in view, I want a formatting like adding a trailing meter.

How get this done?

도움이 되었습니까?

해결책 2

Maybe by providing a property which will return a formatted value:

private int distance = 0;
public int Distance
{
   get { return distance;}
   set { distance = value; OnPropertyChanged("DistanceTxt"); }
}

public string DistanceTxt
{
   get { return distance.ToString() + " meter"; }
}

Then when you bind to DistanceTxt you should get your distance with trailing meter. I've also added OnPropertyChanged in Distance property so that when it changes, your value on the screen updates.

다른 팁

you can format string in the xaml binding...

<TextBlock Text="{Binding Distance, StringFormat={} {0} meter}"/>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top