小编RTD*_*Dev的帖子

Windows Mobile和UWP的其他扩展 - 我应该使用哪个版本

我已经知道为了获得DeviceId,我应该添加对我的项目的引用 - "Windows Mobile Extensions for the UWP"这个SDK随Visual Studio一起提供,并且可以在Windows Universal/Extensions位置的References Manager中找到.但是在列表中有两个这样的位置,它们有不同的版本 - 10.0.10240.0和10.0.10586.0.

我应该使用哪一个?我应该注意哪些差异,或者我应该继续使用新的差异?它们与我想运行我的应用程序的机器上的Windows内部版本号相关吗?

c# win-universal-app windows-10 uwp

7
推荐指数
1
解决办法
1382
查看次数

x:尝试x时绑定StackOverflow:使用TwoWay模式绑定ListView.SelectedItem

我正在尝试使用新的x:Bind绑定ListView.SelectedItem.我的代码:

视图:

//MainPage.xaml:

<Page
x:Class="BrokenListSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BrokenListSample"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="Beige">
    <Grid.RowDefinitions>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>

    <ListView Grid.Row="0" Background="LawnGreen" 
              ItemsSource="{x:Bind ViewModel.MyItems, Mode=OneWay}"
              SelectedItem="{x:Bind ViewModel.BestItem, Mode=TwoWay}"
              Width="300" Height="300"/>

    <ListView Grid.Row="1" Background="LawnGreen" 
              ItemsSource="{Binding MyItems, Mode=OneWay}"
              SelectedItem="{Binding BestItem, Mode=TwoWay}"
              Width="300" Height="300"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)

代码隐藏:

//MainPage.xaml.cs:

using Windows.UI.Xaml.Controls;

namespace BrokenListSample
{
    public sealed partial class MainPage : Page
    {
        public MainPageViewModel ViewModel { get; set; }

        public MainPage()
        {
            InitializeComponent();
            DataContextChanged += (s, e) => { ViewModel = DataContext as MainPageViewModel; };
            DataContext = …
Run Code Online (Sandbox Code Playgroud)

c# win-universal-app windows-10 xbind

5
推荐指数
1
解决办法
674
查看次数

如何检测控件变为可见的时刻

我正在使用 MVVM。在我的视图上,我有一个默认隐藏的控件,它的 Visibility 属性绑定到 ViewModels 属性。

<Grid>
    <TextBox Visibility={Binding IsVisible, Mode=OneWay, Converter={StaticResource MyVisibilityConverter}}/>
<Grid>
Run Code Online (Sandbox Code Playgroud)

在 ViewModel 我有一个属性

private bool _isVisible;
bool IsVisible
{
    get {return _isVisible;}
    set {_isVisible = value; NotifyOfPropetyChanged(() => IsVisible);}
}
Run Code Online (Sandbox Code Playgroud)

非常直截了当,以显示我所做的控制

IsVisible = true;
Run Code Online (Sandbox Code Playgroud)

在我的 ViewModel 中,TextBox 变得可见,按预期工作正常。

我想要做的是在 TextBox 变得可见后将其设置为 Focus。问题是我找不到任何好的解决方案来确定这个特定的控件是否刚好可见并且是我可以设置焦点的时刻。解决方案是测试 LayoutUpdated 事件中的可见性,但这绝对不是代码中最好的事情。有什么更好的解决办法吗?

编辑:澄清 - 我不想通过 MVVM 从 ViewModel 设置焦点。从代码隐藏设置焦点没有问题,因为它是 UI 行为。唯一的问题是如何确定何时执行此操作。在设置 ViewModel 属性和更新布局以匹配其状态之间有一段时间。在那段时间之后,我希望能够捕捉到任何可以通知我“我的可见性已经改变,现在你可以改变焦点”的东西

c# win-universal-app uwp

2
推荐指数
1
解决办法
1986
查看次数

标签 统计

c# ×3

win-universal-app ×3

uwp ×2

windows-10 ×2

xbind ×1