0

The TextWrapping property was setting to Wrap in this code

<ListView Name="answerListView" ItemsSource="{Binding Path=answers}">
  <ListView.ItemTemplate>
    <DataTemplate>
      <StackPanel>
        <Expander Cursor="Hand">
          <Expander.Header>
            <TextBlock Text="{Binding Path=Body_Markdown}" TextWrapping="Wrap"/>
          </Expander.Header>
        </Expander>
      </StackPanel>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

But, now I have added conditional formatting to the TextBlock, i.e., if answer is accepted then show it in green colour. So the code I have used is this:

<ListView Name="answerListView" ItemsSource="{Binding Path=answers}">
  <ListView.ItemTemplate>
    <DataTemplate>
      <StackPanel>
        <Expander Cursor="Hand">
          <Expander.Header>
            <TextBlock Text="{Binding Path=Body_Markdown}">
              <TextBlock.Style>
                <Style TargetType="{x:Type TextBlock}">
                  <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=is_accepted}" Value="true">
                      <Setter Property="Foreground" Value="Green"/>
                      <Setter Property="TextWrapping" Value="Wrap"/>
                    </DataTrigger>
                  </Style.Triggers>
                </Style>
              </TextBlock.Style>
            </TextBlock>
          </Expander.Header>
        </Expander>
      </StackPanel>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

Here, the second line of setting, i.e., Foreground property is not working. Even if I have the same line after <Style TargetType> or TextWrapping="Wrap" in TextBlock, then also it is not working.

amit jha
  • 398
  • 2
  • 6
  • 22

3 Answers3

1

ScrollViewer.HorizontalScrollBarVisibility="Disabled" must been added to ListView. Then this problem will be solved.

amit jha
  • 398
  • 2
  • 6
  • 22
0

Specify the type too:

<Setter Property="TextBlock.Foreground" Value="Green"/>
<Setter Property="TextBlock.TextWrapping" Value="Wrap"/>
StepUp
  • 36,391
  • 15
  • 88
  • 148
  • @amitjha could you show, please, your `Model` and `ViewModel`? – StepUp Mar 09 '16 at 11:33
  • Do I paste the code? It will be difficult to understand. – amit jha Mar 10 '16 at 07:05
  • @amitjha post just necessary code - `Model`, and properties from `ViewModel`. – StepUp Mar 10 '16 at 07:17
  • `ViewModel` - https://docs.google.com/document/d/1zOmetVgWqbJWNCervSRmdF4WnOAnRvuUi6ofxbc4S7E/edit?usp=sharing – amit jha Mar 10 '16 at 07:50
  • @amitjha please read this article and post your code here. You will gain more help from other people, if you post code here. It is more convenient to see in theme, rather than in some other resources. – StepUp Mar 10 '16 at 08:02
0

I guess you are binding a private field, instead of the public property:

{Binding Path=is_accepted} should be replaced by your property {Binding Path=Is_accepted}

This answer assumes that you are using the usual naming which makes fields start by lower case and Properties by Upper case.

NTinkicht
  • 972
  • 2
  • 12
  • 34
  • No, the `is_accepted` value is public property. I have used these properties as it is as they are returned as JSON. – amit jha Mar 09 '16 at 11:38
  • Do I paste the code? It will be difficult to understand. – amit jha Mar 10 '16 at 07:05
  • `ViewModel` - https://docs.google.com/document/d/1zOmetVgWqbJWNCervSRmdF4WnOAnRvuUi6ofxbc4S7E/edit?usp=sharing – amit jha Mar 10 '16 at 07:50
  • Sorry, I don't see any relation between your view and your viewModel. All properties you are binding to in your view are not present in your viewModel... – NTinkicht Mar 10 '16 at 14:37