RadBarCodeQr - 根据图像大小保持与图像相同的距离
我可以控制 RadBarCodeQR,并且我希望它与绑定到它的任何文本与其父级保持相等的间距。
当 RadBarCodeQR
绑定到空字符串时:
当 RadBarCodeQR
绑定到“ssssssssssssssssss”时:
我的代码:
<Grid>
<StackPanel VerticalAlignment="Center">
<TextBox
Text="{Binding QrCode, UpdateSourceTrigger=PropertyChanged}"
Width="300"
Height="30"
Margin="20"/>
<telerik:RadBarcodeQR
Height="100"
Width="100"
Text="{Binding QrCode, UpdateSourceTrigger=PropertyChanged}"
Foreground="Black"
UseLayoutRounding="True">
<telerik:RadBarcodeQR.Style>
<Style TargetType="telerik:RadBarcodeQR">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="telerik:RadBarcodeQR">
<Grid
x:Name="PART_RadBarcodeQR"
Background="White"
Margin="15">
<Image
x:Name="ImageQrCode"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</telerik:RadBarcodeQR.Style>
</telerik:RadBarcodeQR>
</StackPanel>
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为不可能在控件周围保持相等的间距。 QR 码有不同的大小,并具有强制边距,如 文档。这是由规范给出的,不维护它可能会导致二维码不可读。
控件将渲染以下图像: QR 码,正如您从控件模板中看到的那样。该图像包含白色边缘,其厚度根据 QR 码尺寸而变化。
Margin
和Padding
不会影响这一点。话虽这么说,您对控件模板的更改 - 设置Margin="15"
- 破坏了至少绘制规范所需的边距的默认绘制行为。因此,您应该删除自定义控件模板。布局舍入应该不是必需的,因为该控件已优化以无论如何显示 QR 代码。只有实际更改源属性的控件才需要
UpdateSourceTrigger
,该控件不需要,它只读取值。您似乎正在使用旧的 RadBarcodeQR ,即 已弃用。您可以使用 RadBarcode相反:
如果您想要额外的固定大小的空间,您可以为其添加一个
Padding
。I do not think that it is possible to maintain an equal spacing around the control. The QR code comes in different sizes and has a mandatory margin as stated in the documentation. This is given the by specification and not maintaining it can lead to unreadable QR codes.
The control will render an image of the QR code, as you can see from the control template. This image contains a white margin varying in thickness depending on the QR code size. The
Margin
andPadding
do not affect this. That being said, your change to the control template - settingMargin="15"
- breaks the default drawing behavior that at least draws the margin required by the specification.Consequently, you should remove your custom control template. Layout rounding should not be necessary, as the control is optimized to display a QR code anyway. The
UpdateSourceTrigger
is only needed for controls that actually change the source property, this control does not, it only reads the value.You seem to be using the old
RadBarcodeQR
which is deprecated. You can use RadBarcode instead:If you want to have an additional fixed-size space, you can add a
Padding
to it.