我創建了一個名為 "InfoButton "的自定義視圖:
public class InfoButton : ImageButton
{
public string Glyph { get; set; } = "U000F02FD"/span>;
public string Title { get; set; }
public string Text { get; set; }
public InfoButton()
{
Source = new FontImageSource() { Glyph = Glyph, FontFamily = " materialdesign. ttf#materialdesign", Size= (double)new FontSizeConverter().ConvertFromInvariantString("Title"), Color= Color.Black };
背景顏色 = Color.Transparent;
Clicked = InfoButton_Clicked;
}
private void InfoButton_Clicked(object sender, e)。
{
AlertPopup.DisplayAlertPopup(Title, Text, 0, "Close") 。
}
現在我為它創建了一個觸發器:
<models: InfoButton Glyph="& #xF059F; Title="一些標題" Text="一些文本" IsVisible="false"/span> HorizontalOptions="EndAndExpand"/span>>
<models:InfoButton.Triggers>
<MultiTrigger TargetType="{x:Type models:InfoButton}"/span>>
<MultiTrigger.Condition>
< BindingCondition Binding="{Binding isPublic}" Value="true"/>
< BindingCondition Binding="{Binding isReadonly}" Value="false"/>
</MultiTrigger.Condition>
<MultiTrigger.Setters>
< Setter Property="IsVisible" Value="true"/>
< Setter Property="Glyph" Value=& #xF059F;"/>
</MultiTrigger.Setters>
</MultiTrigger>/span>
</models:InfoButton.Triggers>
</models:InfoButton>/span>
但是我在編譯的時候得到了這個錯誤:
。
XFC0001 無法解決 "InfoButton(屬性缺失或訪問器缺失)"型別上的屬性 "Glyph"。
問題可能出在哪里?
謝謝您的幫助。
謝謝你的幫助。
uj5u.com熱心網友回復:
要簡單地解決你的問題,請到解決方案部分。要知道你的代碼失敗的原因,請參閱解釋部分。
解決方案
你必須把你的Glyph屬性變成一個BindableProperty,如下所示
public static readonly BindableProperty GlyphProperty = BindableProperty。 Create(nameof(Glyph), typeof(string) 。typeof(InfoButton), "U000F02FD")。)
public string Glyph
{
get { return (string)GetValue(GlyphProperty); }
set { SetValue(GlyphProperty, value); }
}
解釋
為什么你的代碼在Glyph定義為一個簡單的屬性時失敗了,可以在Setter.Property的檔案中找到解釋,它說。
只有可系結的屬性可以用Setter來設定。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/329857.html
標籤:
