- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想为 Windows 应用商店应用程序创建带有附加属性的自定义文本框。我正在关注this solution 。现在它使用硬编码值作为属性值,但我想使用绑定(bind)来设置值,但它不起作用。我尝试了很多搜索,但没有帮助我解决任何问题。
异常详情是这样的
An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in CustomTextBox.exe but was not handled in user code
WinRT information: Failed to assign to property 'CustomTextBox.Input.Type'.
MainPage.xaml
<!-- local:Input.Type="Email" works -->
<!-- local:Input.Type="{Binding SelectedTextboxInputType}" not working -->
<TextBox x:Name="txt" local:Input.Type="{Binding SelectedTextboxInputType}" Height="30" Width="1000" />
<ComboBox x:Name="cmb" ItemsSource="{Binding TextboxInputTypeList}" SelectedItem="{Binding SelectedTextboxInputType}" Height="30" Width="200"
Margin="451,211,715,527" />
MainPage.xaml.cs
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
DataContext = new ViewModel();
}
}
输入.cs
//InputType is enum
public static InputType GetType(DependencyObject obj)
{
return (InputType)obj.GetValue(TypeProperty);
}
public static void SetType(DependencyObject obj, InputType value)
{
obj.SetValue(TypeProperty, value);
}
public static readonly DependencyProperty TypeProperty =
DependencyProperty.RegisterAttached("Type", typeof(InputType), typeof(TextBox), new PropertyMetadata(default(InputType), OnTypeChanged));
private static void OnTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is InputType)
{
var textBox = (TextBox)d;
var Type = (InputType)e.NewValue;
if (Type == InputType.Email || Type == InputType.URL)
{
textBox.LostFocus += OnLostFocus;
}
else
{
textBox.TextChanged += OnTextChanged;
}
}
}
ViewModel.cs
public class ViewModel : BindableBase
{
public ViewModel()
{
TextboxInputTypeList = Enum.GetValues(typeof(InputType)).Cast<InputType>();
}
private InputType _SelectedTextboxInputType = InputType.Currency;
public InputType SelectedTextboxInputType
{
get { return _SelectedTextboxInputType; }
set { this.SetProperty(ref this._SelectedTextboxInputType, value); }
}
private IEnumerable<InputType> _TextboxInputTypeList;
public IEnumerable<InputType> TextboxInputTypeList
{
get { return _TextboxInputTypeList; }
set { this.SetProperty(ref this._TextboxInputTypeList, value); }
}
}
最佳答案
这是一个非常常见的错误。问题是,绑定(bind)目标不能是 XAML 中的 CLR 属性。这只是规则。绑定(bind)源可以是 CLR 属性,这很好。目标必须是依赖属性。
我们都会收到错误! :)
祝你好运。
关于XamlParseException 无法分配给属性。绑定(bind)不适用于附加属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17971195/
这个 XAMLParseException 让我抓狂!!我在 Visual Studio 1020 中使用 .NET 3.5 这是我的 xaml:
我正在尝试在我的 Silverlight 应用程序中使用第 3 方组件,当我尝试创建控件的实例时,我收到 XamlParseException: {System.Windows.Markup.Xaml
我在设计自己构建的自定义控件的样式时遇到了一些问题。这是控制源: namespace SilverlightStyleTest { public class AnotherControl: T
我在一个非常简单的 wpf 应用程序中正确地在 xaml 代码或属性窗口中设置了窗口图标属性,但 visual studio 总是在运行时抛出 XamlParseException。为什么会这样?(使
当我打开我的 WPF 窗口时出现了这个错误,我不知道是什么导致了这个错误,也不知道如何消除它。错误突出显示并指向 在底部。 'Initialization of 'Outlook_Add_In_Tes
这个问题在这里已经有了答案: XamlParseException after deploying WPF project (10 个答案) 关闭 8 年前。 当我从应用程序中的另一个窗口显示此窗口
我正在尝试使用默认图标之一作为我的 Xaml 代码中按钮的内容。我真的不明白出了什么问题,因为图像在 UI 伪模拟器中显示时加载正常,但当我尝试部署它时,如果我进入 View ,则会抛出 System
我正在使用以下代码在 Window 或 UserControl 中定义 ImageBrush: 如果我在我的正常应用程序中使用它,效果很好。 但是对于我的测试项目,当我尝试实例化它时,我总是会收到此
此 WPF 应用以 .NET 3.5 为目标,并使用 Visual Studio 2010 的 4.0 工具构建(csc.exe 版本为 4.0.30319.1)。 我不确定我看到的这个异常是怎么回事
我有一个定义了 Style 的 ResourceDictionary,它有一个 ControlTemplate 和一个 Binding StringFormat,如下所示: 我在本地运行,一切正常,
我正在尝试使用 Graph#我的 VSPackage 项目中的库,但不幸的是有一些障碍需要克服。这是我所做的: 我将以下所有 DLL 复制到项目根目录中的文件夹/Libraries 中: GraphS
我正在使用静态资源字典,它按以下方式初始化: static ResourceDictionary resource = new ResourceDictionary() { Source =
我创建了一个绑定(bind)了一些文本框的 WPF 应用程序。我使用验证错误来检查值是否正确。验证查找数据库以查看输入的数据是否存在。 如果我输入一个假值,我的验证错误会捕获错误 whitout 问题
我的应用程序是多窗口的。如果发生 XamlParseException,整个应用程序将关闭。 我最多想做的是关闭“负责”此错误的窗口。 你知道实现这一目标的方法吗? 异常示例: System.Wind
我编写了一个可以在我的开发电脑(Window 7)上安装和运行的应用。 开发环境:安装了 .NET 4 和 .NET 3.5 的 Window 7、VS2010 WPF C# 在其他客户端计算机(XP
我正在尝试设置一个简单的 C# 应用程序,我想在其中记录多个 USB 网络摄像头并将它们的提要保存到一些文件中。我正在使用 AForge.NET,因为这似乎是此类应用程序最流行的选项。我可以使用 AF
我随机收到了这个错误,我不知道如何解决它,因为问题的原因是随机发生的。 任何人都可以指导我应该寻找什么,我认为它指向我的 XAML 代码,但我不知道我应该看什么。 System.Windows.Mar
我在几个不同的 WPF 应用程序中使用了一组非常简单的样式。我将此样式存储在一个通用项目的 Xaml 文件中,然后通过合并到 Resources 中添加在 App.xaml在每个项目中。
我一直在尝试部署我的 WPF 应用程序,我使用安装向导创建了一个安装项目。我添加的唯一项目输出是 Primary。构建此程序并安装程序后,一旦我单击桌面上的 exe,我就会弹出一个“我的程序已停止工作
我想为 Windows 应用商店应用程序创建带有附加属性的自定义文本框。我正在关注this solution 。现在它使用硬编码值作为属性值,但我想使用绑定(bind)来设置值,但它不起作用。我尝试了
我是一名优秀的程序员,十分优秀!