Доброго времени суток. Сейчас пытаюсь перенести приложение с wpf на silverlight. Столкнулся с проблемой binding и Convertor. Есть такой код:
| Код | <UserControl xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input" xmlns:mygrid="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" x:Class="SecurigeClientWeb.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:conv="clr-namespace:SecurigeClientWeb.Converters" mc:Ignorable="d" MinHeight="729" MinWidth="1269">
<UserControl.Resources> <conv:LevelToColorConverterBack x:Key="LevelToColorConverterBack"/> <conv:LevelToColorConverterFore x:Key="LevelToColorConverterFore"/> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White"> <Grid.ColumnDefinitions> <ColumnDefinition Width="825" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions>
<my:TabControl Margin="0,0,0,4" x:Name="tabControl1" Width="820" HorizontalAlignment="Left" Grid.Column="0"> <!--Вкладка сигналы основные--> <my:TabItem Header="Сигналы" x:Name="tabItem1"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="60*" /> <RowDefinition Height="35" /> <RowDefinition Height="40*" /> </Grid.RowDefinitions>
<mygrid:DataGrid Grid.Row="0" AutoGenerateColumns="False" HorizontalAlignment="Stretch" Name="GridMainSignal" VerticalAlignment="Stretch" Margin="8,8,8,6" VerticalGridLinesBrush="#C6D7C5" Background="#E5F1E4" IsReadOnly="True" HeadersVisibility="Column" GridLinesVisibility="Vertical" SelectionMode="Extended" VerticalScrollBarVisibility="Auto" SelectionChanged="GridMainSignalSelectionChanged" > <mygrid:DataGrid.RowStyle> <Style TargetType="mygrid:DataGridRow"> <Setter Property="Background" Value="{Binding Level, Converter={StaticResource LevelToColorConverterBack}}"/> <Setter Property="Foreground" Value="{Binding Level, Converter={StaticResource LevelToColorConverterFore}}"/> <!--<EventSetter Event="MouseDoubleClick" Handler="RowDoubleClick"/>--> </Style> </mygrid:DataGrid.RowStyle> </mygrid:DataGrid> </Grid> </my:TabItem> </my:TabControl> </Grid> </UserControl>
|
и соответственно код:
| Код | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Data; using System.Globalization; using System.Windows.Media; using Extension;
namespace SecurigeClientWeb.Converters { public class LevelToColorConverterBack : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { Color col = new Color() { R = 255, B = 0, G = 69, A = 0 }; List<int> d = new List<int>(); return (int)value == 4 ? new SolidColorBrush(col) : new SolidColorBrush(Colors.White); } catch (Exception ex) { ErrorLoger.Call(ex); return new SolidColorBrush(Colors.White); } }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { try { throw new Exception("The method or operation is not implemented."); } catch (Exception ex) { ErrorLoger.Call(ex); return value; } } } }
|
Студия начинает ругаться на строки: <Setter Property="Background" Value="{Binding Level, Converter={StaticResource LevelToColorConverterBack}}"/> <Setter Property="Foreground" Value="{Binding Level, Converter={StaticResource LevelToColorConverterFore}}"/>
[BindingOperations_TargetMustBeFEOrCVS] Аргументы: Недоступны строки ресурсов отладки. Ключ и аргументы часто предоставляют достаточно информации для диагностики проблемы. См. http://go.microsoft.com/fwlink/?linkid=106663&Version=3.0.40818.0&File=System.Windows.dll&Key=BindingOperations_TargetMustBeFEOrCVS в System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding) в Microsoft.Expression.Platform.Silverlight.SilverlightDependencyPropertyImplementation.SetBinding(Object target, Object value) в Microsoft.Expression.DesignModel.Core.InstanceBuilderOperations.SetValue(Object target, IProperty propertyKey, Object value) в Microsoft.Expression.DesignModel.InstanceBuilders.ClrObjectInstanceBuilder.ModifyValue(IInstanceBuilderContext context, ViewNode target, IProperty propertyKey, Object value, PropertyModification modification) в Microsoft.Expression.DesignModel.InstanceBuilders.DependencyObjectInstanceBuilderBase`1.ModifyValue(IInstanceBuilderContext context, ViewNode target, IProperty propertyKey, Object value, PropertyModification modification) в Microsoft.Expression.Platform.Silverlight.InstanceBuilders.DependencyObjectInstanceBuilder.ModifyValue(IInstanceBuilderContext context, ViewNode target, IProperty propertyKey, Object value, PropertyModification modification) в Microsoft.Expression.DesignModel.InstanceBuilders.ClrObjectInstanceBuilder.UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode)
Подскажите, пожалуйста, как решить данную проблему! |