Nerdynosaur
Nerdynosaur

Reputation: 1888

How to draw a circle/ellipse inside a grid cell?

I have a gridview load with data from the database. For the price's row, i want to circle up the number if the price is lower than 5. I building it inside WPF.

It will be something like this :

enter image description here

Upvotes: 0

Views: 2123

Answers (1)

Mike
Mike

Reputation: 1568

If you're using a data template to display the price, you could just draw an ellipse over top of the label.

<DataTemplate>
    <TextBlock Text={Binding Path=Price, StringFormat='{}{0} $'}/>
</DataTemplate>

to

<DataTemplate>
    <Grid>
         <TextBlock Text={Binding Price, StringFormat='{}{0} $'}/>
         <Ellipse Stroke="Orange" 
                  StrokeThickness="2" 
                  Width="50"
                  Height="40"
                  Visibility="{Binding Path=Price, Converter={StaticResource lowPriceToVisiblity}}"/>
    </Grid>
</DataTemplate>

Something to that effect.

The LowPriceToVisibilty converter would just be a simple IValueConverter that takes the price as a parameter and returns the appropriate Visibility value. Alternatively, you could add a Low Price Visibility property to the object being bound to the row and bind to that property.

Upvotes: 1

Related Questions