Стиль переноса текста кнопки WPF

Попробуйте использовать Browser ES Module Loader для загрузки соответствующих модулей.

Добавьте следующую ссылку на скрипт в заголовок:

<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.3.4/bluebird.min.js"></script>
<script nomodule src="https://unpkg.com/browser-es-module-loader/dist/babel-browser-build.js"></script>
<script nomodule src="https://unpkg.com/browser-es-module-loader"></script>

Примечание: соблюдайте порядок, и ссылка bluebird.min.js используется для устранения ошибки «обещание не определено».

29
задан Dave Clemmer 15 August 2011 в 17:51
поделиться

1 ответ

Your second version should work, and does for me, with the caveat that you need to change the TextBlock Text binding:

<!-- in Window.Resources -->
<Style x:Key="fie" TargetType="Button">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type Button}">
        <TextBlock Text="{TemplateBinding Content}" FontSize="20" TextWrapping="Wrap"/>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<!-- then -->
<Button Style="{StaticResource fie}">verylongcaptiongoeshereandwraps/Button>

Note this completely replaces the button style (i.e. you will need to create your own button chrome if you want it).

Regarding your second question, all writeable dependency properties can be set using a Setter. The reason you were unable to set TextWrapping on a Button via a style is that Button does not have a TextWrapping dependency property (or indeed any TextWrapping property). There are no "magic words," just the names of dependency properties.

27
ответ дан itowlson 28 November 2019 в 00:37
поделиться
Другие вопросы по тегам:

Похожие вопросы: