ユーザーがいくつかの色から選択できるようにするセレクターを構築しようとしています。
私はRadListPicker
このコードでコンポーネントを使用しています:
<telerikInput:RadListPicker IsEnabled="True" Grid.Row="4" Header="Tile color: " InlineModeThreshold="3" x:Name="listPicker2" ItemsSource="{Binding Items, Source={StaticResource ColorItems}}" SelectedItem="{Binding TileColor, Mode=TwoWay}">
<telerikInput:RadListPicker.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="{Binding ColorName}" Width="24" Height="24"/>
<TextBlock Text="{Binding ColorName}" Margin="12 -3 0 0"/>
</StackPanel>
</DataTemplate>
</telerikInput:RadListPicker.ItemTemplate>
</telerikInput:RadListPicker>
ColorItems
このクラスはどこですか:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using Microsoft.Phone.Net.NetworkInformation;
namespace Utils
{
public class ColorItems
{
private static readonly ColorItem[] _colorItems =
{
new ColorItem(GetFromRGB(240, 163, 10), "Amber"),
new ColorItem(GetFromRGB(130, 90, 44), "Brown"),
//new ColorItem(GetFromRGB(162, 0, 37), "Crimson"),
//new ColorItem(GetFromRGB(0, 80, 239), "Cobalt"),
new ColorItem(GetFromRGB(27, 161, 226), "Cyan"),
//new ColorItem(GetFromRGB(0, 138, 0),"Emerald"),
new ColorItem(GetFromRGB(96, 169, 23),"Green"),
new ColorItem(GetFromRGB(106, 0, 255),"Indigo"),
new ColorItem(GetFromRGB(164, 196, 0),"Lime"),
new ColorItem(GetFromRGB(216, 0, 115),"Magenta"),
//new ColorItem(GetFromRGB(118, 96, 138),"Mauve"),
new ColorItem(GetFromRGB(109, 135, 100),"Olive"),
new ColorItem(GetFromRGB(250, 104, 0),"Orange"),
new ColorItem(GetFromRGB(244, 114, 208),"Pink"),
new ColorItem(GetFromRGB(229, 20, 0),"Red"),
//new ColorItem(GetFromRGB(100, 118, 135),"Steel"),
//new ColorItem(GetFromRGB(135, 121, 78),"Taupe"),
new ColorItem(GetFromRGB(0, 171, 169),"Teal"),
new ColorItem(GetFromRGB(170, 0, 255),"Violet"),
new ColorItem(GetFromRGB(227, 200, 0),"Yellow"),
};
private static Color GetFromRGB(byte r, byte g, byte b)
{
return new Color {R = r, B = b, G = g, A = 255};
}
public static ColorItem GetFromColor(Color color)
{
return _colorItems.First(c => c.Color.Equals(color));
}
public static ColorItem[] Items
{
get
{
return _colorItems;
}
}
}
}
そしてColorItem
次のとおりです。
public class ColorItem
{
public ColorItem(Color color, string name)
{
this.Color = color;
this.ColorName = name;
}
public Color Color
{
get;
set;
}
public string ColorName
{
get;
set;
}
}
ご覧のとおり、ColorItems._colorItems
コメント行がいくつかあります。それらの線がなければ、すべてがスムーズに進みます。
(エラーとメッセージはイタリア語から翻訳されているため、期待どおりに正確ではない可能性があることに注意してください)
しかし、そのうちの 1 つだけを有効にすると、次のような例外がスローされます。
System.Windows.ni.dll の初回例外 'System.Exception' 致命的なエラー (HRESULT からの例外: 0x8000FFFF (E_UNEXPECTED))
そして、なぜそのような恐ろしい例外がスローされるのかわかりません!
これが完全なスタック トレースです。
System.Windows.ni.dll!MS.Internal.XcpImports.CheckHResult(uint hr) Unknown
System.Windows.ni.dll!MS.Internal.XcpImports.ConvertStringToTypedCValue(System.IntPtr pContext, uint cClrTypeName, string clrTypeName, uint cValue, string value, ref MS.Internal.CValue outVal, out int typeIndex) Unknown
System.Windows.ni.dll!MS.Internal.SilverlightTypeConverter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) Unknown
System.Windows.ni.dll!MS.Internal.Data.DefaultValueConverter.ConvertHelper(object o, System.Type destinationType, System.Globalization.CultureInfo culture, bool isForward) Unknown
System.Windows.ni.dll!MS.Internal.Data.TargetDefaultValueConverter.Convert(object o, System.Type type, object parameter, System.Globalization.CultureInfo culture) Unknown
System.Windows.ni.dll!MS.Internal.Data.DynamicValueConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) Unknown
System.Windows.ni.dll!System.Windows.Data.BindingExpression.ConvertToTarget(object value = "Amber") Unknown
System.Windows.ni.dll!System.Windows.Data.BindingExpression.GetValue(System.Windows.DependencyObject d, System.Windows.DependencyProperty dp) Unknown
System.Windows.ni.dll!System.Windows.DependencyObject.EvaluateExpression(System.Windows.DependencyProperty property = {System.Windows.CoreDependencyProperty}, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry = {System.Windows.EffectiveValueEntry}) Unknown
System.Windows.ni.dll!System.Windows.DependencyObject.EvaluateBaseValue(System.Windows.DependencyProperty property, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, System.Windows.DependencyObject.ValueOperation operation) Unknown
System.Windows.ni.dll!System.Windows.DependencyObject.EvaluateEffectiveValue(System.Windows.DependencyProperty property, System.Windows.EffectiveValueEntry oldEntry, System.Windows.EffectiveValueEntry newEntry, System.Windows.DependencyObject.ValueOperation operation = Reevaluate) Unknown
System.Windows.ni.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.DependencyProperty property = {System.Windows.CoreDependencyProperty}, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry = {System.Windows.EffectiveValueEntry}, System.Windows.DependencyObject.ValueOperation operation) Unknown
System.Windows.ni.dll!System.Windows.DependencyObject.RefreshExpression(System.Windows.DependencyProperty dp) Unknown
System.Windows.ni.dll!System.Windows.Data.BindingExpression.SendDataToTarget() Unknown
System.Windows.ni.dll!System.Windows.Data.BindingExpression.SourceAcquired() Unknown
System.Windows.ni.dll!System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(object sender, System.Windows.DataContextChangedEventArgs e) Unknown
System.Windows.ni.dll!System.Windows.Data.BindingExpression.DataContextChanged(object sender, System.Windows.DataContextChangedEventArgs e) Unknown
System.Windows.ni.dll!System.Windows.FrameworkElement.OnDataContextChanged(System.Windows.DataContextChangedEventArgs e) Unknown
System.Windows.ni.dll!System.Windows.FrameworkElement.OnAncestorDataContextChanged(System.Windows.DataContextChangedEventArgs e = {System.Windows.DataContextChangedEventArgs}) Unknown
System.Windows.ni.dll!System.Windows.FrameworkElement.NotifyDataContextChanged(System.Windows.DataContextChangedEventArgs e = {System.Windows.DataContextChangedEventArgs}) Unknown
System.Windows.ni.dll!System.Windows.FrameworkElement.OnTreeParentUpdated(System.Windows.DependencyObject newParent, bool bIsNewParentAlive) Unknown
System.Windows.ni.dll!System.Windows.DependencyObject.UpdateTreeParent(MS.Internal.IManagedPeer oldParent = null, MS.Internal.IManagedPeer newParent = {System.Windows.Controls.ContentPresenter}, bool bIsNewParentAlive, bool keepReferenceToParent = true) Unknown
System.Windows.ni.dll!MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(System.IntPtr oldParentElement, System.IntPtr parentElement, System.IntPtr childElement, byte bIsParentAlive, byte bKeepReferenceToParent, byte bCanCreateParent) Unknown
[From native to managed]
[From managed to native]
System.Windows.ni.dll!MS.Internal.XcpImports.FrameworkElement_MeasureOverride(System.Windows.FrameworkElement element = {Telerik.Windows.Controls.RadDataBoundListBoxItem}, System.Windows.Size availableSize) Unknown
System.Windows.ni.dll!System.Windows.FrameworkElement.MeasureOverride(System.Windows.Size availableSize) Unknown
System.Windows.ni.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, double inWidth, double inHeight, out double outWidth = 0.0, out double outHeight = 0.0) Unknown
[From native to managed]
[From managed to native]
System.Windows.ni.dll!MS.Internal.XcpImports.UIElement_Measure(System.Windows.UIElement element = {Telerik.Windows.Controls.RadDataBoundListBoxItem}, System.Windows.Size availableSize) Unknown
System.Windows.ni.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) Unknown
telerik.windows.controls.primitives.DLL!Telerik.Windows.Controls.StackVirtualizationStrategy.MeasureContainer(Telerik.Windows.Controls.RadVirtualizingDataControlItem container = {Telerik.Windows.Controls.RadDataBoundListBoxItem}) Unknown
telerik.windows.controls.primitives.DLL!Telerik.Windows.Controls.VirtualizationStrategy.GetContainerForItem(Telerik.Windows.Data.IDataSourceItem item = {Telerik.Windows.Data.DataSourceItem}, int insertAt = 0) Unknown
telerik.windows.controls.primitives.DLL!Telerik.Windows.Controls.StackVirtualizationStrategy.GetContainerForItem(Telerik.Windows.Data.IDataSourceItem item = {Telerik.Windows.Data.DataSourceItem}, int insertAt = 0) Unknown
telerik.windows.controls.primitives.DLL!Telerik.Windows.Controls.VirtualizationStrategy.GetContainerForItem(Telerik.Windows.Data.IDataSourceItem item = {Telerik.Windows.Data.DataSourceItem}, bool insertLast = true) Unknown
telerik.windows.controls.primitives.DLL!Telerik.Windows.Controls.VirtualizationStrategy.ManageLowerViewport(bool recycle = true) Unknown
telerik.windows.controls.primitives.DLL!Telerik.Windows.Controls.RadVirtualizingDataControl.ManageViewport() Unknown
telerik.windows.controls.primitives.DLL!Telerik.Windows.Controls.RadVirtualizingDataControl.BalanceVisualSpace() Unknown
telerik.windows.controls.primitives.DLL!Telerik.Windows.Controls.RadVirtualizingDataControl.OnLoaded(object sender = {Telerik.Windows.Controls.RadDataBoundListBox}, System.Windows.RoutedEventArgs e = {System.Windows.RoutedEventArgs}) Unknown
telerik.windows.controls.primitives.DLL!Telerik.Windows.Controls.RadDataBoundListBox.OnLoaded(object sender = {Telerik.Windows.Controls.RadDataBoundListBox}, System.Windows.RoutedEventArgs e = {System.Windows.RoutedEventArgs}) Unknown
System.Windows.ni.dll!MS.Internal.CoreInvokeHandler.InvokeEventHandler(int typeIndex, System.Delegate handlerDelegate, object sender, object args) Unknown
System.Windows.ni.dll!MS.Internal.JoltHelper.FireEvent(System.IntPtr unmanagedObj, System.IntPtr unmanagedObjArgs, int argsTypeIndex, int actualArgsTypeIndex, string eventName) Unknown
誰が何が起こっているのか知っていますか?