首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使Win8商店应用教程适应WPF

使Win8商店应用教程适应WPF
EN

Stack Overflow用户
提问于 2013-01-08 16:52:55
回答 1查看 901关注 0票数 1

我遵循解释如何使用XAML/C#在Visual中创建拨号的本教程。问题是本教程是针对windows 8商店应用程序的。

知道了这一点,我仍然尝试在WPF应用程序中使用本教程,该应用程序也将支持以前的OSs。

我遇到了一些兼容性问题:

  1. ManipulationMode="All"并不存在,因为本教程的作者为我使用它。它只以Manipulation.ManipulationMode="All"的形式存在,这给了我一个错误:“在指定的元素上操作是不活动的”。我怎么能解决呢?
  2. 作者在ManipulationDelta元素上设置了grid属性,我最初对此没有问题.直到我意识到由VS创建的作者的事件/动作代码隐藏使用了ManipulationDeltaRoutedEventArgs e而不是我的代码隐藏文件中使用的ManipulationDeltaEventArgs e。这意味着我不能使用Position属性(e.Position)轻松地获得用户控件上的鼠标位置。有什么可以替代它的呢?我不认为它可以被支持,因为它被宣布为Win8 .
  3. 在MVVM风格的应用程序中,代码隐藏操作应该在ViewModel中设置。我将如何将该操作代码“绑定”到元素的ManipulationDelta属性?

提前感谢!

我和作者的VS版本都是2012年,所以这不是问题所在。

更新:以下是部分完成的代码:

XAML:

代码语言:javascript
复制
//Manipulation.ManipulationMode="All" => ERROR 'Manipulation is not active on the specified element'
<Grid Manipulation.ManipulationMode="All" ManipulationDelta="Grid_ManipulationDelta_1">
    <Ellipse Fill="#FF7171E6" Margin="30"/>
    <Grid>
        <Grid.RenderTransform>
            <RotateTransform CenterX="225" CenterY="225" Angle="{Binding Angle}"/>
        </Grid.RenderTransform>
        <Ellipse Fill="White" Height="100" VerticalAlignment="Top" Margin="50" Width="100"/>

    </Grid>
</Grid>

代码隐藏:

代码语言:javascript
复制
public partial class dial : UserControl, INotifyPropertyChanged
{
    private int m_Amount;
    public int Amount {...}

    private double m_Angle;
    public double Angle {...}

    public dial()
    {
        InitializeComponent();
        this.DataContext = this;
    }

    private void Grid_ManipulationDelta_1(object sender, ManipulationDeltaEventArgs e)
    {
        this.Angle = GetAngle(e.Position, this.RenderSize); //e.Position doesn't exist in ManipulationDeltaEventArgs...
        this.Amount = (int)(this.Angle / 360 * 100);
    }

    public enum Quadrants : int { nw = 2, ne = 1, sw = 4, se = 3 }
    private double GetAngle(Point touchPoint, Size circleSize)
    {
        var _X = touchPoint.X - (circleSize.Width / 2d);
        var _Y = circleSize.Height - touchPoint.Y - (circleSize.Height / 2d);
        var _Hypot = Math.Sqrt(_X * _X + _Y * _Y);
        var _Value = Math.Asin(_Y / _Hypot) * 180 / Math.PI;
        var _Quadrant = (_X >= 0) ?
            (_Y >= 0) ? Quadrants.ne : Quadrants.se :
            (_Y >= 0) ? Quadrants.nw : Quadrants.sw;
        switch (_Quadrant)
        {
            case Quadrants.ne: _Value = 090 - _Value; break;
            case Quadrants.nw: _Value = 270 + _Value; break;
            case Quadrants.se: _Value = 090 - _Value; break;
            case Quadrants.sw: _Value = 270 + _Value; break;
        }
        return _Value;
    }

    public event PropertyChangedEventHandler PropertyChanged;

}
EN

回答 1

Stack Overflow用户

发布于 2013-10-24 08:09:04

  1. 在WPF中,可以使用IsManipulationEnabled="true“来启用操作。不需要像Windows应用程序那样使用ManipulationMode="All“。
  2. 您可以尝试Mouse.GetPosition(此)获取当前鼠标位置。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14220057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档