Search code examples
wpfdatagridresizedatagridtextcolumn

How to hide left part instead of right part of a WPF datagrid column when resize it?


I have a DataGridTextColumn that show list of batch download URLs. These URLs have same begin part, only different at the end. They are too long to display, so I resize this column by drag column header.
Problem is it hide the right part of these URLs, while I want to hide the left part.
I already think of cut these URLs to keep only need part to display. But this method is not really what I want.
Do you have any way to achieve this, hide left part of column when resize by drag header? Thank!


Solution

  • Turn out it is quite easy:

    <DataGridTextColumn Header="URL" Binding="{Binding Path=url}">
        <DataGridTextColumn.ElementStyle>
            <Style TargetType="TextBlock">
                <Setter Property="HorizontalAlignment" Value="Right"/>
            </Style>
        </DataGridTextColumn.ElementStyle>
    </DataGridTextColumn>