【发布时间】:2020-04-11 05:58:46
【问题描述】:
我正在尝试像本教程一样设置一个切换按钮:
但是,我的按钮内部有一个字体图标。带有字体本身的按钮可以正常工作。问题是当我尝试从 Visual State Manager 设置 ImageSource 属性时。
代码如下:
<FontImageSource x:Key="fileImageSource" Glyph=""
Color="Gray"
FontFamily="{ DynamicResource MaterialIconsFontFamily }"
Size="28" />
<Button Margin="20,10,20,0"
Text="Email Disabled (click to enable)"
FontFamily="{ DynamicResource MaterialIconsFontFamily }"
Style="{StaticResource PaynuverDisabledButtonStyle}"
ImageSource="{StaticResource fileImageSource}">
</Button>
<local:ToggleButton Toggled="OnBoldButtonToggled"
Margin="20,10,20,0"
FontFamily="{ DynamicResource MaterialIconsFontFamily }">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="ToggleStates">
<VisualState Name="ToggledOff">
<VisualState.Setters>
<Setter Property="Text" Value="Email Disabled (click to enable)" />
<Setter Property="Style" Value="{StaticResource DisabledButtonStyle}" />
<Setter Property="ImageSource" Value="{StaticResource fileImageSource}" />
</VisualState.Setters>
</VisualState>
<VisualState Name="ToggledOn">
<VisualState.Setters>
<Setter Property="Text" Value="Email Enabled" />
<Setter Property="Style" Value="{StaticResource ButtonStyle}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</local:ToggleButton>
使用以下代码我得到一个错误:“ToggleButton.ImageSourceProperty 的 PropertyName 不是 ImageSource”
【问题讨论】:
-
得到了它与代码背后的工作。仍然有兴趣了解为什么它在 xaml 中不起作用
-
这个错误是编译错误吗?我在我这边使用了您的代码,但没有看到错误。而且我使用的是最新版本的 Xamarin.forms。
-
不,这是一个运行时错误。我会看看我是否可以在示例项目中尝试一下。
-
好的,一旦您可以在此处上传示例,我们将进行检查。
标签: xaml xamarin xamarin.forms