Reputation: 1697
I have got a class named StockItem.
The class contains some instance properties including Quantity.
The class contains some static properties including Cart and CartTotalPrice.
Cart type is ObservableCollection.
CartTotalPrice returns the cart total price.
I have created a UserControl named UCOrder allowing the user to add items into the cart.
I have created another UserControl allowing the user to change the quantity of a cart item.
I have declared a TextBlock in the markup of UCOrder.
I want to bind the TextBlock to the static property StockItem.CartTotalPrice so the TextBlock displays the current CartTotalPrice.
How can I do it ?
Any help will be greatly appreciated
Upvotes: 0
Views: 957
Reputation: 11051
<TextBlock Text="{Binding Source={x:Static StockItem.CartTotalPrice}}"/>
It might seem odd at first, but Source
tells us which is the actual source of our binding, which is usually the DataContext
, but we setit to use our static property. With path we would now supply a property on the source object, but because we already have in source what we want, we don't set path which is by default "." which means "Take the source directly".
But please note the comments under your question. While i just answered your question, i also consider it a bad idea to do it like that, because of the already mentioned reasons.
Upvotes: 2