开发者

Bind a value to other in WPF UserControl

I have an WPF UserControl that has a property IsSelected. In that control I have a Border(the control is circular, si I have a circle-Ellipse) around, that should appear only if the control IsSelected.

<GeometryDrawing>
    <GeometryDrawing.Pen>

        <!--   HERE ==> Thickness = IIF(IsSelected, 2, 0) -->
        <Pen Brush="blue" Thickness="2"/>

    </GeometryDrawing.Pen>
    <GeometryDrawing.Geometry>
        <GeometryGroup>
            <EllipseGeometry x:Name="Border" 
                Center="0,0" RadiusX="5" Ra开发者_Python百科diusY="5"/>
        </GeometryGroup>
    </GeometryDrawing.Geometry>
</GeometryDrawing>

How can I bind the pen's thickness?


You'll need a Control Template with TemplateBinding. You will also need a TypeConverter that will transform boolean value into thickness integer.

Something like:

<Pen Thickness="{TemplateBinding IsSelected, 
                 Converter={StaticResource BooleanToSizeConverter}" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜