【问题标题】:RoutedPropertyChangedEventArgs for WPF slider - "type or namespace could not be found"WPF 滑块的 RoutedPropertyChangedEventArgs -“找不到类型或命名空间”
【发布时间】:2015-09-25 16:24:43
【问题描述】:

我正在关注 this example 创建一个简单的滑块,我可以在我的 Windows 应用商店应用程序中使用它的值。

但是,当我开始创建 Something_ValueChanged(根据示例)并尝试添加 double 类型的 RoutedPropertyChangedEventArgs 作为此方法的参数时,我收到标准的“找不到类型或命名空间名称”错误.

我尝试查看其他示例,例如this,这似乎表明我缺少“使用”导入,例如 System.Windows 和 System.Windows.Controls。但是,我也发现后者丢失了(类型或命名空间......)!

这是我在 MainPage.xaml 和 MainPage.xaml.cs 中使用的相关代码部分:

xaml:

<Grid ...>
    <Grid ...>
        ...
        <Slider  Name="BinSize" Width="300" Height="20"
                     Background="Gray" Maximum="100" Minimum="0"
                     Canvas.Left="50" Canvas.Top="50"
                     ValueChanged="BinSize_ValueChanged"/>
    </Grid>
</Grid>

cs:

private void BinSize_ValueChanged(object sender,
    RoutedPropertyChangedEventArgs<double> e)
{
    //nothing yet
}

谁能告诉我我在这里做错了什么?

【问题讨论】:

    标签: c# .net wpf xaml windows-8.1


    【解决方案1】:

    如果您正在为 Windows 8 应用程序编码,则方法签名/内容应如下所示:

        private void BinSize_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
        {
            string msg = String.Format("Current value: {0}", e.NewValue);
            this.textBlock1.Text = msg;
        }
    

    Here 是页面底部的 MSDN 示例。

    您所遵循的教程大部分适用于 Windows 8 应用程序,但它是为 WPF(Windows Presentation Foundation)应用程序设计的,因此可能会略有不同。每当您遇到错误时,我都会在 Google 上搜索您正在使用的项目的名称并找到 Windows 8 版本。

    我希望这会有所帮助。祝你好运。

    【讨论】:

    • 谢谢,一旦我得到这个工作,我会检查并添加为接受的答案!
    • 不是问题,很高兴为您提供帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-25
    • 2017-07-12
    • 2011-05-13
    • 2021-03-01
    • 2020-08-13
    • 2018-11-18
    相关资源
    最近更新 更多