Silverlight 导航应用程序用户控制状态

发布于 2024-08-09 03:46:10 字数 151 浏览 2 评论 0原文

我有一个有 5 页的导航应用程序。我还有一个带有 3 个单选按钮的用户控件。我的应用程序中的所有 5 个页面都使用此用户控件。默认情况下,第一个单选按钮被选中。但是,如果用户单击第三个单选按钮并且我转到另一个页面,我希望我的用户控件仍将第三个单选按钮显示为选中状态。我该如何完成这项任务?

I have a navigation app with 5 pages. I also have a usercontrol with 3 radio buttons. This usercontrol is used by all 5 pages in my app. By default the first radio button is selected. However if the user clicks the 3rd radio button and I go to another page I want my usercontrol to still show that 3rd radio button as selected. How do I go about accomplishing this task?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

春风十里 2024-08-16 03:46:10

有几种方法可以做到这一点。也许最简单的方法是创建一个类,该类具有单选按钮所选项目的属性。将此类的实例作为资源添加到应用程序,然后将单选按钮绑定到此静态资源。

public class MyState
{
  public string SelectedRadioValue {get;set;}
}

在 Application_Startup 的 App.xaml.cs 中添加:

var state = new MyState()
Resources.Add("myState", state);

然后在绑定中您可以设置:

SelectedValue="{Binding Source={StaticResource myState},Path=SelectedRadioValue}"

您还可以采取其他方法。

There are several ways you could do this. Probably the most simple way is to create a class that has a property for the selected item of the radio buttons. Add an instance of this class as a resource to the application and then bind the radio buttons to this static resource.

public class MyState
{
  public string SelectedRadioValue {get;set;}
}

In the App.xaml.cs in the Application_Startup add:

var state = new MyState()
Resources.Add("myState", state);

Then in the bindings you can set:

SelectedValue="{Binding Source={StaticResource myState},Path=SelectedRadioValue}"

There are other approaches you could take as well.

瑕疵 2024-08-16 03:46:10

是否可以在视图控件之外显示此控件?听起来它应该放置在显示视图的位置之外的 MainPage.xaml 上。通过这种方式,可以使用一个控件,并且可以将其值提供给所有视图。

Is it possible to show this control outside of the View control? It sounds like it should be placed on the MainPage.xaml outside of the place where the views are displayed. This way the one control is used and its value can be made available to all of the views.

冷血 2024-08-16 03:46:10

如果您只是想在用户在页面之间导航时保​​存页面的状态,那么实现此目的的最简单方法是

NavigationCacheMode="Required"

在页面的 xaml 的第一个元素中设置:。

If you are just looking to save the state of the page as the user navigates between pages then the easiest way of accomplishing this is to set:

NavigationCacheMode="Required"

in the first element of the xaml for your page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文