自定义 XAML 属性
我见过一个库,允许我在 XAML 中执行此操作,它根据用户是否处于某个角色来设置控件的可见性: s:Authorization.RequiresRole="Admin"
将该库与我的数据库一起使用需要一堆我现在无法真正完成的编码。最终,这就是我想知道的...
我已经从我的 SPROC 收到了经过身份验证的用户角色,并且它当前作为属性存储在我的 App.xaml.cs 中(对于最终解决方案来说不是必需的,目前仅供参考)。我想创建一个属性(依赖属性?附加属性?),它允许我说出与其他库具有的内容非常相似的内容:RequiresRole =“Admin”,如果用户不处于管理员角色,这将折叠可见性。谁能指出我在这方面的正确方向?
编辑 构建授权类后,出现以下错误: “XML 命名空间 clr-namespace:TSMVVM.Authorization 中的类型‘HyperlinkButton’上不存在属性‘RequiredRole’”
我正在尝试添加此 xaml:
<HyperlinkButton x:Name="lnkSiteParameterDefinitions"
Style="{StaticResource LinkStyle}"
Tag="SiteParameterDefinitions"
Content="Site Parameter Definitions"
Command="{Binding NavigateCommand}"
s:Authorization.RequiredRole="Admin"
CommandParameter="{Binding Tag, ElementName=lnkSiteParameterDefinitions}"/>
当我开始输入 s:Authorization.RequiredRole="Admin" ,智能感知拾取了它。我尝试将 typeof(string) 和 typeof(ownerclass) 设置为 HyperlinkButton 以查看是否有帮助,但没有帮助。有什么想法吗?
I've seen a library that allows me to do this inside my XAML, which sets the visibility of the control based on whether or not the user is in a role:
s:Authorization.RequiresRole="Admin"
Using that library with my database requires a bunch of coding that I can't really do right now. Ultimately here's what I want to know...
I have received the authenticated users role from my SPROC, and its currently stored in my App.xaml.cs as a property (not necessary for the final solution, just FYI for now). I want to create a property (dependency property? attached property?) that allows me to say something very similar to what the other library has: RequiresRole="Admin", which would collapse the visibility if the user is not in the Admin role. Can anyone point me in the right direction on this?
EDIT
After building the authorization class, I get the following error:
"The property 'RequiredRole' does not exist on the type 'HyperlinkButton' in the XML Namespace clr-namespace:TSMVVM.Authorization"
I'm trying to add this xaml:
<HyperlinkButton x:Name="lnkSiteParameterDefinitions"
Style="{StaticResource LinkStyle}"
Tag="SiteParameterDefinitions"
Content="Site Parameter Definitions"
Command="{Binding NavigateCommand}"
s:Authorization.RequiredRole="Admin"
CommandParameter="{Binding Tag, ElementName=lnkSiteParameterDefinitions}"/>
When I started typing the s:Authorization.RequiredRole="Admin", intellisense picked it up. I tried setting the typeof(string) and typeof(ownerclass) to HyperlinkButton to see if that would help, but it didn't. Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
附加属性是实现它的方式。您应该像这样定义一个属性:
PS:当您意识到您在询问 Silverlight 时已经太晚了。虽然我相信它在那里以同样的方式工作,但我只在 WPF 上尝试过。
Attached property is the way to implement it. You should define a property like this:
PS: Have noticed too late that you were asking about Silverlight. Though I believe it works in the same way there, but I've tried it only on WPF.