This is a migrated thread and some comments may be shown as answers.

How to resize RadButton in RadToolBar?

6 Answers 226 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
hvduc
Top achievements
Rank 1
hvduc asked on 14 Feb 2012, 11:04 AM
Hi telerik,
I'm using Telerik controls for Silverlight 2011 Q3 SP1 ver. 2011.3.1220.1040
I added a RadButton into a RadToolBar like below sample code:
<telerik:RadToolBar x:Name="radTB"
              Height="40">
  <telerik:RadButton HorizontalContentAlignment="Center"
               Background="Transparent"
               BorderThickness="0"
               Width="40">
      <StackPanel>
          <Image Width="16"
              Height="16"
              Source="/BusinessApplication1;component/Image16.png" />
          <TextBlock Text="Click"></TextBlock>
      </StackPanel>
  </telerik:RadButton>             
</telerik:RadToolBar>
In code-behind, I modified width of that RadButton to 200 but nothing changes in UI.
Then how can I modified width of a RadButton because I need change width of control in RadToolbar in many situations.
Hope you can provide a project sample soon.

Thanks.

6 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 17 Feb 2012, 11:01 AM
Hello Hoàng,

I tried to reproduce the issue but I wasn't able to. I basically added one more button and on its click event I changed the Width of the RadButton and it worked as expected. Can you send us a sample project reproducing the issue so that we can further investigate it?

Thank you in advance for your cooperation on the matter.

Regards,
Tina Stancheva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
hvduc
Top achievements
Rank 1
answered on 17 Feb 2012, 12:50 PM
Hi telerik,
My actual scenario like this:
- I created a class inherit Radbutton and resize its width based on its content.
- In UI, I add my button to a toolbar and it can't  be resized. If my button not in toolbar, it can be resized normally.
If my button in stackpanel, I must call method MyStackPanel.Measure(e.NewSize)   to update changes of button to stackpanel but it doesn't work with toolbar.
<telerik:RadToolBar x:Name="radTB"
                        Height="40">
                    <MyApp:MyButton HorizontalContentAlignment="Center"
                            Background="Transparent"
                            BorderThickness="0"
                            Width="40">
                        <StackPanel>
                            <Image Width="16"
                        Height="16"
                        Source="/ResizeButton1;component/Image16.png"/>
                            <TextBlock Text="Click"/>
                        </StackPanel>
                    </MyApp:MyButton>
                </telerik:RadToolBar>

Public Class MyButton
    Inherits RadButton
 
    Protected Overrides Function MeasureOverride(availableSize As System.Windows.Size) As System.Windows.Size
        Me.Width = availableSize.Width + 200
        Return MyBase.MeasureOverride(New Size(Me.Width, availableSize.Height))
    End Function
End Class
0
Tina Stancheva
Telerik team
answered on 22 Feb 2012, 12:47 PM
Hi Hoàng,

Thank you for getting back to us and sharing your approach. Unfortunately the RadToolBar logic doesn't allow such an approach - changing the Width of the button during its measuring process. It would be better to simply change the Width of the button somewhere else in your logic.

However as I am not sure what are the requirements of your scenario, I cannot suggest a better approach for the moment. But if you can further elaborate on what you need to implement in your application, I will be able to suggest another way for going about it.

Kind regards,
Tina Stancheva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
hvduc
Top achievements
Rank 1
answered on 25 Feb 2012, 02:12 AM
Hi Telerik,
Actually, I need localize all content of my buttons so width of button need to be changed based on the width of content when form is opened because I want margin of content in all buttons is the same.
My method is using my button inherited from RadWindow. It works great in all scenerio except for buttons in RadToolBar.
Can you suggest another way for me?
0
hvduc
Top achievements
Rank 1
answered on 25 Feb 2012, 02:19 AM
Hi Telerik,
Actually, I need localize all content of my buttons so width of button need to be changed based on the width of content when form is opened because I want margin of content in all buttons is the same.
My method is using my button inherited from RadWindow. It works great in all scenerio except for buttons in RadToolBar.
Can you suggest another way for me?
0
Tina Stancheva
Telerik team
answered on 29 Feb 2012, 03:16 PM
Hi Hoàng,

If I understand your scenario correctly, you need to dynamically change the width of the RadButton based on the size of its content. If this is the case, then you can remove the Width/Height properties of the control and instead set its HorizontalAlignment/VerticalAlignment properties to a value different from Stretch (for example HorizontalAlignment="Left" and VerticalAlignment="Center") and define the same Padding property for all buttons as the Padding property defines the size of the padding space between the border of the button and its content.

Then changing the length of the content will automatically resize the button accordingly. Please let me know if this approach will work for you or if I'm missing something.

Kind regards,
Tina Stancheva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
ToolBar
Asked by
hvduc
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
hvduc
Top achievements
Rank 1
Share this question
or