2017-04-19 106 views
0

我想为传递其他绑定值的转换器参数传递模型属性值。Xamarin Forms将模型值传递给绑定转换器参数

<Label FontSize="{Binding MediumLabelTextSize}" 
     Text="{Binding FeedHome.QuestionBody, 
       Converter={StaticResource HideLongTextConverter}}"/> 
<Label FontSize="{Binding SmallLabelTextSize}" 
     IsVisible="{Binding IsQuestionReadMoreVisible}" 
     Text="Read more"> 
     <Label.GestureRecognizers> 
      <TapGestureRecognizer Command="{Binding ReadMoreCommand}" 
          CommandParameter="{Binding .}"/> 
     </Label.GestureRecognizers> 
</Label> 

我想通过FeedHome.QuestionBody像IsQuestionReadMoreVisible转换器参数。 我该怎么办?

+0

技术观点不应该发布一些东西来查看模型。 Command和CommandParameter是唯一的例外。如果你的视图中有数据,Viewmodel应该已经注意到了这一点 – Emad

+0

IsVisible =“{Binding IsQuestionReadMoreVisible,ConverterParameter = {Binding Source = {x:Reference LabelName},Path = Text}}”这也可以,否则你可以使用传递BindingContext,如“{Binding BindingContext.FeedHome.QuestionBody,Source = {x:Reference MainPage}}” – Dilmah

+0

为什么你不在你的viewModel中的ReadMoreCommand中使用你的FeedHome.QuestionBody属性?当点击标签时,你知道这个属性的价值,或不? – puko

回答

0

请尝试这个

文本= “{结合的HeaderText,转换器= {StaticResource的caseConverter},ConverterParameter = U}}” ISVISIBLE = “{结合IsEditMode,转换器= {StaticResource的boolInverter}}”