C# Canvas Scrollbar isn't working / isn't "active" - c#

I got a problem with the ScrollViewer in Visual Studio.
First off, I'm german and my english isn't that good, so I hope you guys understand me.
Here's the problem:
I made a timetable in C# and it's way too big for the window to display everything on the timetable. Then I added scrollbars but the problem is that they're not "active". Means I can't scroll even though they're visible. I have no idea what isn't working there, so I thought you could help me. Hopefully somebody knows how to solve the problem.
Here's the code for the scrollviewer:
<ScrollViewer HorizontalScrollBarVisibility="Visible VerticalScrollBarVisibility="Visible" Margin="10,0,0,0" >
<Canvas x:Name="uiCVStundenplan" Background="White" Margin="116,65,10,10" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
</Canvas>
</ScrollViewer>
As I said before, the timetable is way too big for the window. So I don't understand why the scrollbars aren't active.
I hope I explained it well enough for you. I'm counting on you!♥

I think there is a mistake in your code. You forget a double quote after HorizontalScrollBarVisibility, after Visible.
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" Margin="10,0,0,0" >
<Canvas x:Name="uiCVStundenplan" Background="White" Margin="116,65,10,10" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
</Canvas>
</ScrollViewer>

Related

Bringing a WPF border to front - a part of TextBox's autosuggestion project

I have a few issues with my autosuggestion project - I went with having a layout like this :
<Border Margin="30,125,44,77" BorderBrush="Black"
BorderThickness="1" Background="White">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel Name="resultStack"></StackPanel>
</Border>
To display items of my autosuggestion list. The autosuggestion part works just fine but I have a problem with the layout. When I launch my window, both the border and scroll viewer elements are behind all the other parts of my window...
Before autosuggest fires :
After autosuggest fires :
This is obviously not what I wanted. I want both the border and scrollviewer elements to be in front of all other elements.
If more code has to be provided for this problem to be solved, please let me know.
Okay, the ZIndex tip from user TyCobb worked for me. I could've used a lower value if I didn't have other ZIndexes assigned in other places.
<Border Margin="30,125,44,77" Panel.ZIndex="5"
BorderThickness="1" Background="White" Visibility="Collapsed">
<Border.BorderBrush>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ActiveBorderColorKey}}"/>
</Border.BorderBrush>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel Name="resultStack"></StackPanel>
</ScrollViewer>
</Border>

WPF ScrollView and TextBlock

What am I doing wrong?
The following code works:
<ScrollViewer x:Name="scrollChatMessages">
<TextBlock x:Name="txtChatMessages" TextWrapping="Wrap"/>
</ScrollViewer>
But once I touch it up with the designer so it looks neater and doesn't take over the entire Grid, the ScrollView doesn't scroll the content of the Scrollblock anymore:
<ScrollViewer x:Name="scrollChatMessages" HorizontalAlignment="Left" Height="181" Margin="95,10,0,0" VerticalAlignment="Top" Width="300">
<TextBlock x:Name="txtChatMessages" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Height="181" Width="300"/>
</ScrollViewer>
Could someone explain this behaviour to me?
Thanks in advance!
Without a good Minimal, Complete, and Verifiable code example it's impossible to say for sure. But you can see that the Designer has added a bunch of new property values for both elements. In particular, the ScrollViewer and TextBlock have been set to have the same exact width and height.
Naturally, with the contained element having exactly the correct dimensions to fit within the ScrollViewer, there's no need to scroll to see all of it. You need to remove the Width and Height property values from the TextBlock.
I solved it by placing it inside of a Grid.
<Grid x:Name="gridChatMessages" HorizontalAlignment="Left" Height="181" Margin="95,10,0,0" VerticalAlignment="Top" Width="300">
<ScrollViewer x:Name="scrollChatMessages">
<TextBlock x:Name="txtChatMessages" TextWrapping="Wrap"/>
</ScrollViewer>
</Grid>

WPF stackpanel scrolling issues

i have this in my window and i'll be adding items programmatically to these stacks. problem is i can't scroll through my stuff. i have tried everything that i can find online but i couldn't.
<Border x:Name="Border_Output" Width="463" Height="463" CornerRadius="30"
BorderThickness="0" Background="White">
<Grid>
<StackPanel x:Name="Restaurant_SearchOutputStack"/>
<StackPanel x:Name="Item_SearchOutputStack"/>
<StackPanel x:Name="Order_OutputStack"/>
<StackPanel x:Name="Menu_OutputStack"/>
</Grid>
</Border>
If you have a stackpanel, it is assigned the size of it's items, so the scrollerbar won't appear.
From this article:
As you can see, having a ListBox in a StackPanel causes the
ScrollViewer to disappear, since the StackPanel gives its children the
entire size they need, rendering the collection without the
ScrollViewer.
i found the answer.. it was to have it this way instead.
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid>
<StackPanel x:Name="Restaurant_SearchOutputStack"/>
<StackPanel x:Name="Item_SearchOutputStack"/>
<StackPanel x:Name="Order_OutputStack"/>
<StackPanel x:Name="Menu_OutputStack"/>
</Grid>
</ScrollViewer>
and because when i use one stack i collapse the others what i want happens correctly. thanks anyways guys.

How to implement parallax background on a grouped GridView inside Semantic Zoom

I'm trying to implement a nice-looking horizontally scrolled gridview inside my app. I have already implemented it using the Q42.WinRT library like this:
<Canvas>
<StackPanel Orientation="Horizontal" Height="768">
<StackPanel.RenderTransform>
<CompositeTransform
TranslateX="{Binding ElementName=MyScrollViewer, Path=HorizontalOffset, Converter={StaticResource ParallaxConverter}}" />
</StackPanel.RenderTransform>
<Image Source="/Assets/3.jpg" Width="1366" Stretch="UniformToFill"/>
<Image Source="/Assets/1.jpg" Stretch="UniformToFill"/>
<Image Source="/Assets/2.jpg" Stretch="UniformToFill"/>
</StackPanel>
</Canvas>
<ScrollViewer
x:Name="MyScrollViewer"
HorizontalScrollMode="Enabled"
HorizontalScrollBarVisibility="Auto"
VerticalScrollMode="Disabled"
VerticalAlignment="Center"
Height="768">
<GridView>
//...my gridview goes here
</GridView> </ScrollViewer>
Everything works fine, however in my app I need to use semantic zoom, and I found that semantic zoom does NOT WORK properly when put inside a ScrollViewer.
Generally all the solutions for parallactic backgrounds that I found on the internet implement some kind of functionality over a scrollviewer, which is unfortunate for me as I cannot use it.
Can anybody think of another way to achieve the desired effect?
Generally putting GridViews inside a ScrollViewer is not a great idea since they already have ScrollViewers inside of them...
You should put your 2 GridViews inside a SemanticZoom.
Perhaps you could edit the template for your GridView and put a parallax background in there - perhaps as a Canvas with some content that responds to the ViewChanged events on the GridView.
EDIT*
You inspired me to try to write a ParallaxBackgroundBehavior for the Toolkit. :)
You can see an early version here. There is also a sample included.

Stackpanel in a button

I'm supposed to make a user-control using WPF, and now i'm bumping into a weird problem.
I came up with a kinda weird solution to get an image along with some text in a button, like this:
<Button Height="24" Width="100" Name="btn_change">
<StackPanel Width="90">
<Image Source="Images\11.png" Width="24" Height="18" HorizontalAlignment="Left" Panel.ZIndex="-1" Stretch="Uniform"></Image>
<Label Content="Change" HorizontalAlignment="Right" Margin="0,-18,0,0" Height="20" Padding="0,0,0,0" />
</StackPanel>
</Button>
This worked perfectly, until i started using a MVVM Framework (Caliburn.Micro). From that point on the images no longer show up in the buttons, just the text. I can't figure out why it doesn't work.
Maybe someone with knowledge of MVVM Frameworks can explain this or give me a solution :)
Thanks in advance!
EDIT:
Never mind! I looked it over thanks to H.B. and it seemed I moved the View to a subfolder. I changed the image source from "Images\11.png" to "..\Images\11.png" and it worked!
Just change your image source from "Images\11.png" to "..\Images\11.png" and it will work.

Categories