我遵循解释如何使用XAML/C#在Visual中创建拨号的本教程。问题是本教程是针对windows 8商店应用程序的。
知道了这一点,我仍然尝试在WPF应用程序中使用本教程,该应用程序也将支持以前的OSs。
我遇到了一些兼容性问题:
ManipulationMode="All"并不存在,因为本教程的作者为我使用它。它只以Manipulation.ManipulationMode="All"的形式存在,这给了我一个错误:“在指定的元素上操作是不活动的”。我怎么能解决呢?ManipulationDelta元素上设置了grid属性,我最初对此没有问题.直到我意识到由VS创建的作者的事件/动作代码隐藏使用了ManipulationDeltaRoutedEventArgs e而不是我的代码隐藏文件中使用的ManipulationDeltaEventArgs e。这意味着我不能使用Position属性(e.Position)轻松地获得用户控件上的鼠标位置。有什么可以替代它的呢?我不认为它可以被支持,因为它被宣布为Win8 .ViewModel中设置。我将如何将该操作代码“绑定”到元素的ManipulationDelta属性?提前感谢!
我和作者的VS版本都是2012年,所以这不是问题所在。
更新:以下是部分完成的代码:
XAML:
//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>代码隐藏:
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;
}发布于 2013-10-24 08:09:04
https://stackoverflow.com/questions/14220057
复制相似问题