Search This Blog

Wednesday, July 22, 2015

How to bind to a parent DataContext property in WPF

WPFRelativeSource > FindAncestor

Bind to a parent DataContext property example



IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.YourParentProperty}"


Add a Border to a TextBlock WPF

WPF > Windows > Controls > Border

If you want to display a border around your content, you must place the elements within a parent Border element.

Example: Add a Border to a TextBlock

<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left"                     VerticalAlignment="Top">
            <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap"  Text="TextBlock"  VerticalAlignment="Top"/>
 </Border>


Tuesday, July 7, 2015

Table in RichTextBox WPF C#

WPF > Controls  > ContentControl > RichTextBox > Table

XAML

<Window x:Class="Editor.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <RichTextBox>
            <FlowDocument>
                <Table>
                    <TableRowGroup>
                        <TableRow>
                            <TableCell>
                                <Paragraph>Cell1</Paragraph>
                            </TableCell>
                            <TableCell>
                                <Paragraph>Cell2</Paragraph>
                            </TableCell>
                        </TableRow>
                    </TableRowGroup>
                </Table>
            </FlowDocument>
        </RichTextBox>
    </Grid>
</Window>