[Silverlight] Detach C1flexgrid scroll bar

Source: Internet
Author: User
Tags silverlight

A Scene introduction

The scrollbar in the C1flexgrid control of Silverlight 5.0 is embedded in the range of C1flexgrid width and height, as shown in the following:

(No scroll bars are hidden) (hide the scroll bar that comes with it)

The definition of row height is as follows:

<C1:C1flexgrid x:Name="Flxg" Width="+" Height=" the"               Grid.Row="0" headersvisibility="None"                Alternatingrowbackground="AliceBlue" Background="Lightgray"               gridlinesvisibility="All" Gridlinesbrush="Black">    <C1:C1flexgrid.Rows>        <C1:Row Height=" the" />        <C1:Row Height=" the" />    </C1: C1flexgrid.rows>    <C1:C1flexgrid.Columns>        <C1:Column Width=" the" />        <C1:Column Width=" the" />        <C1:Column Width=" the" />    </C1: C1flexgrid.columns></C1: C1flexgrid>

Even if the C1flexgrid line and width are set to all row height and or all column widths , the self-brought scroll bar will still be displayed, but actually if you hide the scroll bar of the C1flexgrid, the effect looks much better. So I just want to hide the C1flexgrid from the scroll bar, and then add one of my own scroll bars to the bottom or the right to manipulate the scrolling c1flexgrid.

Two solution ideas

1, C1flexgrid property scrollposition can get or set the offset of its own scroll bar;

2, C1flexgrid and rolling related events have, scrollpositionchanging and scrollpositionchanged, breakpoint debugging experiment can know when the execution to scrollpositionchanged event, the Scrollposition property value of C1flexgrid is updated to the offset of the scroll bar;

3. When C1flexgrid triggers the scrollpositionchanged event, the offset value of the custom ScrollBar (ScrollBar) is updated, and when the valuechanged event of the custom ScrollBar (ScrollBar) is triggered, Update C1flexgrid's Scrollposition property value;

4. Note that the Scrollposition attribute of C1flexgrid is negative, the value of ScrollBar is positive and the positive and negative conversion is noted;

5, scrollbar the Maximum property: Set the scroll bar can slide the maximum value, should be equal to the C1flexgrid visual range outside the length or width value;

6, ScrollBar viewportsize property: Set the length value of the bar on the scroll bar, should be equal to the width of the C1flexgrid value, that is, the length of the visible range or width value;

Three-part code

Initialize scrollbars based on C1flexgrid

1 // <summary>2 /// Initialize scroll bar according to C1flexgrid3 // </summary>4 /// <param name= "FlexGrid" ></param>5 Private voidInitscrollbar (C1flexgrid FlexGrid)6{7 Doubleallcolumnswidth = 0;8 Doubleallrowsheight = 0;9 foreach(Column ColinchFlexgrid.columns)Ten{ OneAllcolumnswidth + = Col. Width.value; A} - foreach(Row rowinchFlexgrid.rows) -{ theAllrowsheight + = row. Height; -} - //When all rows are high and greater than the height of the C1flexgrid box, the vertical scroll bar is available - if(Allrowsheight > Flexgrid.height) +{ -scrollbarvert.visibility = visibility.visible; + the maximum value of the//vertical scroll bar should be the height beyond the visible range in C1flexgrid AScrollbarvert.maximum = Allrowsheight-flexgrid.height; at //The length of the bar on the scrollbar should be the height of the C1flexgrid visible range -Scrollbarvert.viewportsize = Flexgrid.height; -Scrollbarhori.smallchange = 1;minimum value of//roll Change -} - Else -{ inscrollbarvert.visibility = visibility.collapsed; -} to //When all column widths are greater than the width of the C1flexgrid box, the horizontal scroll bar is available + if(Allcolumnswidth > Flexgrid.width) -{ thescrollbarhori.visibility = visibility.visible; * the maximum value of the//horizontal scroll bar should be the width remaining in the C1flexgrid beyond the visible range $Scrollbarhori.maximum = Allcolumnswidth-flexgrid.width;Panax Notoginseng the length of the white bar on the scrollbar should be the width of the C1flexgrid visible range -Scrollbarhori.viewportsize = Flexgrid.width; theScrollbarhori.smallchange = 1;minimum value of//roll Change +} A Else the{ +scrollbarhori.visibility = visibility.collapsed; -} $}
View Code

C1flexgrid Triggering a scrolling event

  1  //c1flexgrid Scroll events   2  private  void  flxg _scrollpositionchanged (object  sender, EventArgs e)  3  { 4  point position = Flxg. Scrollposition; //C1flexgrid the position of the current scroll bar   5  txtmsg1.text = "c1flexgrid: " + position. X + " "+ position. Y  6  //update custom scroll bars   7  scrollbarhori.value =-position. X  8  scrollbarvert.value =-position. Y  9 } 
View Code

Horizontal/Vertical scroll bar Slide Event

1 //Horizontal scroll bar2 Private voidScrollbarhori_valuechanged (Objectsender, routedpropertychangedeventargs<Double> E)3{4 //Note that the value of the ScrollBar control ScrollBar is positive and is the opposite of the C1flexgrid scroll bar position5Flxg. Scrollposition =NewPoint (-scrollbarhori.value, Flxg. SCROLLPOSITION.Y);6}7 8 //Vertical scroll bar9 Private voidScrollbarvert_valuechanged (Objectsender, routedpropertychangedeventargs<Double> E)Ten{ One //Note that the value of the ScrollBar control ScrollBar is positive and is the opposite of the C1flexgrid scroll bar position AFlxg. Scrollposition =NewPoint (FLXG. Scrollposition.x,-scrollbarvert.value); -}
View CodeFour something

C1flexgrid in the scrollbar Part I do not think it is very delicate, when the length of the C1flexgrid, the width is set to exactly equal all the rows Takawa, all the column width, as said above C1flexgrid comes from the scroll bar will be displayed, If this time to fully display the C1flexgrid in the lower right corner of the cell, the scroll bar offset is ( -3,-3);

So if I follow the code above and then pull the custom two scroll bars to the bottom or rightmost, then the scrollbar offset of C1flexgrid is 3, as shown in:

The offset is shown as ( -200,-150) when the scroll bar is pulled to the extreme

When the last cell is fully displayed, the offset is displayed as ( -203,-153)

So in fact, when you set the maximum offset value for a custom scrollbar scrollbar, you should have an additional 3, which is Scrollbarvert.maximum = Allrowsheight-flexgrid.height + 3;

This is completely synchronized;

Five Resources download

Source code sample Project Download Http://files.cnblogs.com/files/memento/SLC1FlexGridScorllbar.2015.03.20.zip

[Silverlight] Detach C1flexgrid scroll bar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.