C# VisualStateManager.SetVisualStateGroups UWP
我正在使用Xamarin在Android、iOS和UWP中开发一个应用程序 有人能解释一下为什么以下在Android和iOS上运行良好,但在UWP上却不行 我有一个从Xamarin.Forms.Button继承的自定义控件:C# VisualStateManager.SetVisualStateGroups UWP,c#,xamarin,xamarin.forms,uwp,C#,Xamarin,Xamarin.forms,Uwp,我正在使用Xamarin在Android、iOS和UWP中开发一个应用程序 有人能解释一下为什么以下在Android和iOS上运行良好,但在UWP上却不行 我有一个从Xamarin.Forms.Button继承的自定义控件: 公共类CustomButton:Xamarin.Forms.Button { 公共自定义按钮() { BorderWidth=按钮样式。BorderWidth; VisualStateManager.SetVisualStateGroups( 这 新的VisualState
公共类CustomButton:Xamarin.Forms.Button
{
公共自定义按钮()
{
BorderWidth=按钮样式。BorderWidth;
VisualStateManager.SetVisualStateGroups(
这
新的VisualStateGroupList()
{
新的VisualStateGroup()
{
州=
{
ButtonStyle.NormalState,
按钮样式。按状态,
按钮样式。鼠标翻转,
按钮样式。禁用状态
}
}
});
}
}
公共静态类按钮样式
{
公共静态颜色文本Color{get;}=Colors.ButtonText;
公共静态颜色背景颜色{get;}=Colors.subtleacent;
公共静态双边框宽度{get;}=Parameters.ButtonOrderWidth;
公共静态双拐角半径(双FontSize)=>0.5*FontSize;
公共静态VisualState NormalState{get;}=
新VisualState
{
Name=“正常”,
二传手=
{
新设置程序{Property=Button.TextColorProperty,Value=Colors.ButtonText},
新设置程序{Property=Button.BackgroundColorProperty,Value=Colors.subtleacent},
新设置程序{Property=Button.BorderColorProperty,Value=Colors.ButtonText},
新设置器{Property=Button.PaddingProperty,Value=new Thickness(5,0)},
新设置器{Property=Button.MarginProperty,Value=new Thickness(0,0)}
}
};
公共静态VisualState PressedState{get;}=
新VisualState
{
Name=“按下”,
二传手=
{
新设置程序{Property=Button.TextColorProperty,Value=Colors.ButtonText},
新设置程序{Property=Button.BackgroundColorProperty,Value=Colors.subtleacent},
新设置器{Property=Button.BorderColorProperty,Value=Colors.Accent},
新设置器{Property=Button.PaddingProperty,Value=new Thickness(0,0)},
新设置器{Property=Button.MarginProperty,Value=new Thickness(5,0)}
}
};
公共静态VisualState MouseOverState{get;}=
新VisualState
{
Name=“PointerOver”,
二传手=
{
新设置程序{Property=Button.TextColorProperty,Value=Colors.ButtonText},
新设置程序{Property=Button.BackgroundColorProperty,Value=Colors.subtleacent},
新设置器{Property=Button.BorderColorProperty,Value=Colors.Accent},
新设置器{Property=Button.PaddingProperty,Value=new Thickness(5,0)},
新设置器{Property=Button.MarginProperty,Value=new Thickness(0,0)}
}
};
公共静态VisualState禁用状态{get;}=
新VisualState
{
Name=“已禁用”,
二传手=
{
新设置程序{Property=Button.BorderColorProperty,Value=Colors.Disabled},
新设置程序{Property=Button.TextColorProperty,Value=Colors.Disabled},
新的Setter{Property=Button.BackgroundColorProperty,Value=Colors.GrayVeryLight},
新设置器{Property=Button.PaddingProperty,Value=new Thickness(5,0)},
新设置器{Property=Button.MarginProperty,Value=new Thickness(0,0)}
}
};
}
在UWP上,VisualState的“正常”和“按下”工作正常,但其他的工作正常,我只得到Xamarin.Forms.Button的默认样式“PointerOver”或“Disabled”
正如我之前所说,在Android和iOS上的工作与预期一样
谢谢
在UWP上,VisualState的“正常”和“按下”工作正常,但其他的工作正常,我只得到Xamarin.Forms.Button的默认样式“PointerOver”或“Disabled”
从“官方”派生出名为“CommonState”的默认VisualStateManager
可视状态组,该组具有以下可视状态:“正常”“禁用”“聚焦”“选定”
,它不包含指针上方
状态,因此指针上方
将不起作用。对于android和ios,它们没有指针覆盖
状态。如果确实需要此功能,我们建议您使用自定义按钮渲染,并在本机按钮控件上设置PointerOver
在UWP上,VisualState的“正常”和“按下”工作正常,但其他的工作正常,我只得到Xamarin.Forms.Button的默认样式“PointerOver”或“Disabled”
从“官方”派生出名为“CommonState”的默认
VisualStateManager
可视状态组,该组具有以下可视状态:“正常”“禁用”“聚焦”“选定”
,它不包含指针上方
状态,因此指针上方
将不起作用。对于android和ios,它们没有指针覆盖
状态。如果您确实需要此功能,我们建议您使用自定义按钮渲染,并在本机按钮控件上设置PointerOver
。好的,我知道PointerOver不起作用。但是残疾人呢?禁用状态不工作是的,我发现,它看起来Disabled
对按钮不起作用,我已经测试过了