尝试选择1
如何使图钉的内容溢出图钉图标。似乎我只能在图钉内显示非常小的文本。我尝试过简单地将内容值设置为文本、创建TextBlock和将TextBlock设置为内容,但结果都是相同的。
pushpin.Background = new SolidColorBrush(Colors.Yellow);
pushpin.Foreground = new SolidColorBrush(Colors.Black);
TextBlock ppContent = new TextBlock();
//ppContent.TextWrapping = TextWrapping.WrapWithOverflow;
ppContent.Text = "heyyyyyyyy yyyyyyyyy";
ppContent.Width = 333;
ppContent.Height = 333;
pushpin.Content = ppContent ;
pushpin.Tag = pinLabel;
pushpin.Location = location;

正如你在上面的图片中所看到的,文本被切断了!
尝试选择2
我尝试过的另一种方法是定义一个ControlTemplate。我可以通过在ControlTemplate中定义一个ControlTemplate来成功地使Application.Resources显示一个新的图标。
<ControlTemplate x:Key="PushPinTemplate">
<Grid>
<TextBlock Name="textBlock1" Text="{Binding Content}" Grid.Column="0" Grid.Row="0" Foreground="Black"></TextBlock>
<Rectangle Width="10" Height="10" Margin="0 35 0 0">
<Rectangle.Fill>
<ImageBrush ImageSource="pack://application:,,,/Images/DragHandleWhite.gif"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>并应用这样的模板;
pushpin.Template = (ControlTemplate)Application.Current.Resources["PushPinTemplate"];现在的问题是,我无法从后面的代码中访问textBlock1,从而将值设置为“
任何帮助都是非常感谢的,我在这个问题上被困了很长一段时间:
发布于 2014-05-23 18:01:27
对于选项二:将TextBlock的文本绑定更改为
Text="{TemplateBinding Content}"然后,只需更改图钉的内容属性就可以更改文本。
编辑:确保您的ControlTemplate有正确的TargetType集。在你的情况下应该是普什平。在XAML中,使用其他名称空间映射(它表示xmlns),您需要添加:
xmlns:maps="clr-namespace:Microsoft.Maps.MapControl.WPF";assembly=Microsoft.Maps.MapControl.WPF"那么你的TargetType应该是
TargetType="maps:Pushpin"https://stackoverflow.com/questions/23835617
复制相似问题