Silverlight 的一个问题(在线等,非常感谢)

didiaogao 2012-03-27 01:48:59
首先我要封装了一个style ,如下

<!-- Style RwPushPinStyle-->
<Style x:Name="RoadWarriorPinStyle" TargetType="DeepProtoControls:DevPin">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DeepProtoControls:DevPin">
<Grid>
<Grid.RenderTransform>
<ScaleTransform x:Name="PART_PinScale" />
</Grid.RenderTransform>

<Image Cursor="Arrow" x:Name="PART_Image" Width="64" Height="64" Source="Resources/roadwarrior.png" Stretch="Uniform" RenderTransformOrigin="0.5,0.5" />
<Grid x:Name="toolTip" Background="Transparent" ToolTipService.ToolTip="RoadWarrior" />

<Grid x:Name="PART_Balloon" Width="60" Height="60" Cursor="Arrow">

<Grid.Resources>
<Storyboard x:Name="PART_ShowInfoBalloon">
<DoubleAnimation Storyboard.TargetName="BalloonScale" Storyboard.TargetProperty="ScaleX" From="0.25" To="1" Duration="0:0:0.1"/>
<DoubleAnimation Storyboard.TargetName="BalloonScale" Storyboard.TargetProperty="ScaleY" From="0.25" To="1" Duration="0:0:0.1"/>
</Storyboard>
</Grid.Resources>

<Grid x:Name="PART_MinBalloon" Cursor="Hand" HorizontalAlignment="Right" Margin="0,-12,-12,0" VerticalAlignment="Top" >
<Image x:Name="PART_InfoImage" Source="Resources/information.png" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>

<Grid x:Name="PART_MaxBalloon" Visibility="Collapsed" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="42,-128,-200,43" RenderTransformOrigin="0,1" Width="210" Height="144">
<Grid.RenderTransform>
<ScaleTransform x:Name="BalloonScale" />
</Grid.RenderTransform>

<StackPanel Margin="0,0,0,0" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" >
<Border Background="#AA000000" CornerRadius="5" Padding="6,2,6,2" Margin="0,4,0,0" >
<StackPanel >
<TextBlock
x:Name="lblDescription"
TextAlignment="Left"
Foreground="White"
FontSize="10"
MinHeight="64"
MaxHeight="108"
MinWidth="162"
MaxWidth="212"
TextWrapping="Wrap" />
</StackPanel>
</Border>
</StackPanel>
</Grid>

</Grid>

</Grid>

</ControlTemplate>
</Setter.Value>
</Setter>
</Style>



然后我在封装的DevPin(和app.xaml不在同一个类库)中需要调用这个style中的控件。但在sytle写在app.xaml中,可以取到。
但把style放到和devPin在一个类库下的generic.xaml文件中,确掉不到。
用GetTemplateChild 或者this.Resources都不行。如下
_tb = this.Resources["lblDescription"] as TextBlock;
这个是怎么回事??


第二个问题。其中有一个C类库 。里面有A类,B类。

我在主工程MailPage.xaml中引用A类B类,,这样是可以的。
但我不想把B类暴露给客户,所以我需要在C类库中新建一个D.xaml文件,把A类和B类进去。然后在从主工程MainPage.xaml中,直接去引用D.xaml就可以了。但在MailPage.xaml.cs中,无法获取A类的所有属性和对象。是咋回事



...全文
107 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
E次奥 2012-03-30
  • 打赏
  • 举报
回复
写到D类中,试试。


private A a1=new A();
public A A1
{
get { return a1; }
set { a1 = value; }
}


调用的时候new D().A1.属性。
sundayX 2012-03-28
  • 打赏
  • 举报
回复
270641500
didiaogao 2012-03-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sundayx 的回复:]
第一个问题:

public override void OnApplyTemplate()
{
base.OnApplyTemplate();
this.lightBackground = (Grid)base.GetTemplateChild("lightBackground");
_tb = this.GetTemplateChild("lblDescription"……
[/Quote]
能否加下QQ,说下第二个问题
sundayX 2012-03-27
  • 打赏
  • 举报
回复
第一个问题:
DevPin.xaml写上面你的style,并将style的Name去掉。
然后在themes文件夹下的generic.xaml文件中包含DevPin.xaml。
在DevPin.xaml.cs文件中
public DevPin()
{
this.DefaultStyleKey = typeof(DevPin);
}

public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_tb = this.GetTemplateChild("lblDescription") as TextBlock;
}
sundayX 2012-03-27
  • 打赏
  • 举报
回复
第一个问题:

public override void OnApplyTemplate()
{
base.OnApplyTemplate();
this.lightBackground = (Grid)base.GetTemplateChild("lightBackground");
_tb = this.GetTemplateChild("lblDescription") as TextBlock;
}
取不到?

第二个问题:不明白啥意思。A类和B类是两个class,还是两个usercontrol,D又是什么,是usercontrol还是只一个xaml文件?

8,734

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧