아주 간단한 lookless 컨트롤을 사용하고 있으며, 템플릿 바인딩 중 하나를 사용할 수 없습니다. 컨트롤에는 두 개의 종속성 속성이 있습니다. 하나는 문자열이고 int는 하나는 아닙니다.Silverlight databind int가 보이지 않는 컨트롤이 작동하지 않습니다.
는 CSHARP 코드는 다음과 같습니다
using System;
using System.Windows;
using System.Windows.Controls;
namespace ControlDemo
{
public class TextControlLookless : Control
{
#region Title
public static readonly DependencyProperty ChartTitleProperty =
DependencyProperty.Register("ChartTitle", typeof(string), typeof(TextControlLookless),
null);
public String ChartTitle
{
get { return (string)GetValue(ChartTitleProperty); }
set
{
SetValue(ChartTitleProperty, value);
}
}
#endregion
#region Value
public static readonly DependencyProperty ChartValueProperty =
DependencyProperty.Register("ChartValue", typeof(int), typeof(TextControlLookless),
null);
public int ChartValue
{
get { return (int)GetValue(ChartValueProperty); }
set
{
SetValue(ChartValueProperty, value);
}
}
#endregion
#region ctor
public TextControlLookless()
{
this.DefaultStyleKey = typeof(TextControlLookless);
}
#endregion
}
}
그리고 컨트롤의 XAML은 다음과 같습니다
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ControlDemo">
<Style TargetType="local:TextControlLookless">
<Setter Property="ChartTitle" Value="Set Title" />
<Setter Property="ChartValue" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:TextControlLookless">
<Grid x:Name="Root">
<Border BorderBrush="Black" BorderThickness="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Text="{TemplateBinding ChartTitle}" />
<TextBlock Text="{TemplateBinding ChartValue}" Grid.Row="1" />
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
내가 페이지에이를 넣어, 내가 볼 수 ChartTitle (Set Title 또는 내가 설정 한 것)이지만 ChartValue는 결코 나타나지 않습니다. 그 유형을 문자열로 변경하면, 그 문자열이 나타나기 때문에, 뭔가 빠져 있어야합니다.
두 번째 작품이 마음에 들지만, 내 머리 속에서 더 잘 흐른다. –