Ok, so I am not that versed in the mighty WPF, but I attempted an interesting project to jump into it. I have made a simple RSS/ATOM feed viewer that pulls the HTML out of and RRS or ATOM feed and sticks it in a Browser control which is added to a stack panel... which is the content of a ScrollViewer. Whew. Anyways the problem is, I am doing this all in the code behind and have found that the ScrollViewer doesn't work, or isn't recognizing the size of the content, so there is no scrolling. I have tried setting the size of the viewer and the content, as well as attempted the min and max sizes.
What am I missing here? The content is there, and if I load this before the WPF is loaded it works but once I try to change, or "Clear" children from a control, the scrollviewer stops working right.
<Window x:Class="Heine.Syndication.xkcd.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Feed Viewer" Height="600" Width="800">
<StackPanel>
<ToolBarPanel >
<ToolBar>
<ComboBox Margin="0" Width="100" Name="cbController">
<MenuItem Header="xkcd" Name="xkcdMI"/>
<MenuItem Header="9Gag" Name="nineGagMI"/>
<MenuItem Header="reddit" Name="redditMI"/>
</ComboBox>
</ToolBar>
</ToolBarPanel>
<Grid Name="svMain">
</Grid>
</StackPanel>
</Window>
public MainWindow()
{
InitializeComponent();
cbController.SelectedIndex = 0;
xkcdMI.Click += xkcdMI_Click;
nineGagMI.Click += nineGagMI_Click;
redditMI.Click += redditMI_Click;
Load("http://xkcd.com/atom.xml");
}
private void Load(string feedUrl)
{
var reader = XmlReader.Create(feedUrl);
var feed = SyndicationFeed.Load<SyndicationFeed>(reader);
svMain.Children.Clear();
var tmpStack = new StackPanel();
foreach (var item in feed.Items)
{
var browser = new WebBrowser();
GetHTML(ref browser, item);
tmpStack.Children.Add(browser);
}
svMain.Children.Add(new ScrollViewer()
{
Content = tmpStack,
Height = svMain.Height
});
}
ScrollViewerrefusing to scroll? is it not displaying the items at all? - Fabian TampStackpanelcontrols are notorious for messing up scrollbars. I'd suggest for a start to check out the MVVM pattern and how bindings and data templates are applied in WPF rather than attempting to create and assign child controls in code ala WinForms. - Steve Py