Skip to content

Instantly share code, notes, and snippets.

@kaitlynbrown
Last active December 8, 2017 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaitlynbrown/6e1fb254794431a3b739d7618e3442b2 to your computer and use it in GitHub Desktop.
Save kaitlynbrown/6e1fb254794431a3b739d7618e3442b2 to your computer and use it in GitHub Desktop.
StackOverFlow post with error
On a page where I am displaying a receipt to a user, I have a section which lists the subtotal, any taxes, and the total. Since the taxes applicable vary by region and based on the products being sold, the number of rows in this section will vary. For example, here are 3 separate orders, one with GST and PST, one with just GST, and one with neither:
[![GST+PST][1]][1]
[![GST Only][2]][2]
[![No Tax][3]][3]
I've accomplished this by putting just the SubTotal in the grid in XAML, and adding the rest in the code-behind in a method I call from the ViewModel. However, I'd really like to avoid doing it this way, so I'm wondering if there is an approach to accomplishing this which doesn't require having a bunch of code in the View's code-behind and having the ViewModel know about the View.
A ListView is not suitable here for a number of reasons:
- These controls are inside of a scrollview, and having a listview inside of a scrollview causes all sorts of weird problems.
- I would like to keep the columns as narrow as their widest element. This is possible with a Grid, but a ListView would take up the entire width of its parent no matter what.
- I neither need nor want for my rows to be selectable
So is there a way I can do this entirely from the ViewModel without resorting to using a ListView?
[1]: https://i.stack.imgur.com/k7ypX.png
[2]: https://i.stack.imgur.com/hUOyi.png
[3]: https://i.stack.imgur.com/jEMYL.png
On a page where I am displaying a receipt to a user, I have a section which lists the subtotal, any taxes, and the total. Since the taxes applicable vary by region and based on the products being sold, the number of rows in this section will vary. For example, here are 3 separate orders, one with GST and PST, one with just GST, and one with neither:
![GST+PST](https://i.stack.imgur.com/k7ypX.png)
![GST Only](https://i.stack.imgur.com/hUOyi.png)
![No Tax](https://i.stack.imgur.com/jEMYL.png)
I've accomplished this by putting just the SubTotal in the grid in XAML, and adding the rest in the code-behind in a method I call from the ViewModel. However, I'd really like to avoid doing it this way, so I'm wondering if there is an approach to accomplishing this which doesn't require having a bunch of code in the View's code-behind and having the ViewModel know about the View.
A ListView is not suitable here for a number of reasons:
- These controls are inside of a scrollview, and having a listview inside of a scrollview causes all sorts of weird problems.
- I would like to keep the columns as narrow as their widest element. This is possible with a Grid, but a ListView would take up the entire width of its parent no matter what.
- I neither need nor want for my rows to be selectable
So is there a way I can do this entirely from the ViewModel without resorting to using a ListView?
On a page where I am displaying a receipt to a user, I have a section which lists the subtotal, any taxes, and the total. Since the taxes applicable vary by region and based on the products being sold, the number of rows in this section will vary. For example, here are 3 separate orders, one with GST and PST, one with just GST, and one with neither:
![GST+PST](https://i.stack.imgur.com/k7ypX.png)
![GST Only](https://i.stack.imgur.com/hUOyi.png)
![No Tax](https://i.stack.imgur.com/jEMYL.png)
I've accomplished this by putting just the SubTotal in the grid in XAML, and adding the rest in the code-behind in a method I call from the ViewModel. However, I'd really like to avoid doing it this way, so I'm wondering if there is an approach to accomplishing this which doesn't require having a bunch of code in the View's code-behind and having the ViewModel know about the View.
A `ListView` is not suitable here for a number of reasons:
- These controls are inside of a `ScrollView`, and having a `ListView` inside of a `ScrollView` causes all sorts of weird problems.
- I would like to keep the columns as narrow as their widest element. This is possible with a `Grid`, but a `ListView` would take up the entire width of its parent no matter what.
- I neither need nor want for my rows to be selectable
So is there a way I can do this entirely from the ViewModel without resorting to using a `ListView`?
On a page where I am displaying a receipt to a user, I have a section which lists the subtotal, any taxes, and the total. Since the taxes applicable vary by region and based on the products being sold, the number of rows in this section will vary. For example, here are 3 separate orders, one with GST and PST, one with just GST, and one with neither:
<img src="https://i.stack.imgur.com/k7ypX.png">
<img src="https://i.stack.imgur.com/hUOyi.png">
<img src="https://i.stack.imgur.com/jEMYL.png">
I've accomplished this by putting just the SubTotal in the grid in XAML, and adding the rest in the code-behind in a method I call from the ViewModel. However, I'd really like to avoid doing it this way, so I'm wondering if there is an approach to accomplishing this which doesn't require having a bunch of code in the View's code-behind and having the ViewModel know about the View.
A `ListView` is not suitable here for a number of reasons:
- These controls are inside of a `ScrollView`, and having a `ListView` inside of a `ScrollView` causes all sorts of weird problems.
- I would like to keep the columns as narrow as their widest element. This is possible with a `Grid`, but a `ListView` would take up the entire width of its parent no matter what.
- I neither need nor want for my rows to be selectable
So is there a way I can do this entirely from the ViewModel without resorting to using a `ListView`?
On a page where I am displaying a receipt to a user, I have a section which lists the subtotal, any taxes, and the total. Since the taxes applicable vary by region and based on the products being sold, the number of rows in this section will vary. For example, here are 3 separate orders, one with GST and PST, one with just GST, and one with neither:
![GST+PST](https://i.stack.imgur.com/k7ypX.png)
![GST Only](https://i.stack.imgur.com/hUOyi.png)
![No Tax](https://i.stack.imgur.com/jEMYL.png)
I've accomplished this by putting just the SubTotal in the grid in XAML, and adding the rest in the code-behind in a method I call from the ViewModel. However, I'd really like to avoid doing it this way, so I'm wondering if there is an approach to accomplishing this which doesn't require having a bunch of code in the View's code-behind and having the ViewModel know about the View.
A `ListView` is not suitable here for a number of reasons:
- These controls are inside of a `ScrollView`, and having a `ListView` inside of a `ScrollView` causes all sorts of weird problems.
- I would like to keep the columns as narrow as their widest element. This is possible with a `Grid`, but a `ListView` would take up the entire width of its parent no matter what.
- I neither need nor want for my rows to be selectable
So is there a way I can do this entirely from the ViewModel without resorting to using a `ListView`?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment