Search Results

Search found 5961 results on 239 pages for 'wpf 4 5'.

Page 48/239 | < Previous Page | 44 45 46 47 48 49 50 51 52 53 54 55  | Next Page >

  • WPF zoom canvas and maintain scroll position

    - by Alex McBride
    I have a Canvas element, contained within a ScrollViewer, which I'm zooming using ScaleTransform. However, I want to be able to keep the scroll position of the viewer focused on the same part of the canvas after the zoom operation has finished. Currently when I zoom the canvas the scroll position of the viewer stays where it was and the place the user was viewing is lost. I'm still learning WPF, and I've been going backwards and forwards a bit on this, but I can't figure out a nice XAML based way to accomplish what I want. Any help in this matter would be greatly appreciated and would aid me in my learning process. Here is the kind of code I'm using... <Grid> <ScrollViewer Name="TrackScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> <Canvas Width="2560" Height="2560" Name="TrackCanvas"> <Canvas.LayoutTransform> <ScaleTransform ScaleX="{Binding ElementName=ZoomSlider, Path=Value}" ScaleY="{Binding ElementName=ZoomSlider, Path=Value}"/> </Canvas.LayoutTransform> <!-- Some complex geometry describing a motor racing circuit --> </Canvas> </ScrollViewer> <StackPanel Orientation="Horizontal" Margin="8" VerticalAlignment="Top" HorizontalAlignment="Left"> <Slider Name="ZoomSlider" Width="80" Minimum="0.1" Maximum="10" Value="1"/> <TextBlock Margin="4,0,0,0" VerticalAlignment="Center" Text="{Binding ElementName=ZoomSlider, Path=Value, StringFormat=F1}"/> </StackPanel> </Grid>

    Read the article

  • Handle exceptions with WPF and MVVM

    - by Jon Cahill
    I am attempting to build an application using WPF and the MVVM pattern. I have my Views being populated from my ViewModel purely through databinding. I want to have a central place to handle all exceptions which occur in my application so I can notify the user and log the error appropriately. I know about Dispatcher.UnhandledException but this does not do the job as exception that occur during databinding are logged to the output windows. Because my View is databound to my ViewModel the entire application is pretty much controlled via databinding so I have no way to log my errors. Is there a way to generically handle the exceptions raised during databinding, without having to put try blocks around all my ViewModel public's? Example View: <Window x:Class="Test.TestView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="TestView" Height="600" Width="800" WindowStartupLocation="CenterScreen"> <Window.Resources> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> </Window.Resources> <StackPanel VerticalAlignment="Center"> <Label Visibility="{Binding DisplayLabel, Converter={StaticResource BooleanToVisibilityConverter}}">My Label</Label> </StackPanel> </Window> The ViewModel: public class TestViewModel { public bool DisplayLabel { get { throw new NotImplementedException(); } } } It is an internal application so I do not want to use Wer as I have seen previously recommended.

    Read the article

  • Report viewer in wpf and selection formula

    - by shabi
    I have a WPF application that I would like to present SQL Server Reporting Services sql 2008 reports in. I understand we have to use host widow control and then in report viewer control. I want to use remote processing mode. My code sample is : I have added namespaces: using System.Windows.Forms; using System.Windows.Forms.Integration; using Microsoft.Reporting; using Microsoft.ReportingServices; using Microsoft.Reporting.WinForms; My XAML: xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" xmlns:wfr="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms" Title="ReportHost" Height="300" Width="300"> <Grid> <wfi:WindowsFormsHost Height="100" Margin="39,27,39,0" Name="winFormsHost" VerticalAlignment="Top" > <wfr:ReportViewer x:Name="rptViewer" ProcessingMode="Remote" /> </wfi:WindowsFormsHost> </Grid> Code: rptViewer.ServerReport.ReportServerUrl = new Uri("http://mymachine-:8080/ReportServer_myreports"); rptViewer.ServerReport.ReportPath="/Reports/mytestreport.rdl"; rptViewer.ServerReport.Refresh(); My question is that how how can I set selection formula in microsoft report viewer control [like crystal report]. Or miscroft provided any this else which behave like selection formula in crystal reports. And when I run the code it show only report viewer in host window control but not the report data in window. Please some one provide me all step list, Which I have to fallow to get required result with sample code. Quick response will be appricated.

    Read the article

  • WPF relaycommand from usercontrol

    - by pilsdumps
    Hi, I'm new to WPF and in the spirit of trying to do things the correct way have tried to implement MVVM in my application. I've made use of the frequently mentioned article by Josh Smith, and apart from making me realise how little I know, it has left me a little stumped. Specifically, I have a page that uses the RelayCommand object to handle a button directly on the page and this is fine. However, the button (save) will ultimately be on a user control that will also contain other buttons and the control will be used on a number of pages. My question is this; how do I relay the command from the user control to the page (ie viewmodel) containing it? If I bind to the command public ICommand SaveCommand { get { if (_saveCommand == null) { _saveCommand = new RelayCommand( param => this.Save(), param => this.CanSave ); } return _saveCommand; } } on the user control, I would need to use a Save method on the user control itself, when in fact I should be handling it on the viewmodel. Can anyone help?

    Read the article

  • WPF Global style definitions with .Net4

    - by stiank81
    I have a WPF application using .Net3.5. I'm now trying to change the target framework to .Net4, but I run into some problems with my style definitions. I have most style definitions in a separate project. Some are global styles that address specific components like e.g. <Button> controls that doesn't have explicit style defined. And some are styles defined with a key such that I can reference them explicitly. Now, the controls that have an explicit style referenced are displayed correctly after changing to .Net4. This goes also for explicit style references in the separate project. However, all global styles are disabled. Controls like e.g. <Button>, that I use the global style for everywhere, now appears without any style. Why?! Does .Net4 require a new way for defining global styles? Or referencing ResourceDictionaries? Anyone seen similar problems? I have tried replacing my style definitions with something very simple: <Style TargetType="{x:Type Button}"> <Setter Property="Background" Value="Red"></Setter> </Style> It still doesn't work. I moved this directly to the ResourceDictionary of the app.xaml, and then it works. I moved it to the ResourceDictionary referenced by the one in app.xaml, and it still works. This ResourceDictionary merges several dictionaries, one of them is the dictionary where the style was originally defined - and it doesn't work when being defined there. Note that there are other style definitions in the same XAML that does work - when being explicitly defined.

    Read the article

  • WPF DatePicker IsEnabled property not changing appearance

    - by Jonathan
    I think I have found an issue with the DatePicker in the toolkit, perhaps some of you gurus can check it out. The issue is when setting the IsEnabled property of the DatePicker. If set in XAML, it stays grey even if you set the IsEnabled to true at run time. The same goes for the other way around should it start off being enabled. The button just changes the IsEnabled property of the date picker, you will see that when it becomes enabled, the style remains grayed out. <Window x:Class="WpfApplication3.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:tk="http://schemas.microsoft.com/wpf/2008/toolkit" Title="Window1" Height="300" Width="300"> <StackPanel> <tk:DatePicker x:Name="txtDate" IsEnabled="False"></tk:DatePicker> <Button Height="25" Click="Button_Click"></Button> </StackPanel> </Window> private void Button_Click(object sender, RoutedEventArgs e) { txtDate.IsEnabled = !txtDate.IsEnabled; }

    Read the article

  • Binding update adds news series to WPF Toolkit chart (instead of replacing/updating series)

    - by Mal Ross
    I'm currently recoding a bar chart in my app to make use of the Chart class in the WPF Toolkit. Using MVVM, I'm binding the ItemsSource of a ColumnSeries in my chart to a property on my viewmodel. Here's the relevant XAML: <charting:Chart> <charting:ColumnSeries ItemsSource="{Binding ScoreDistribution.ClassScores}" IndependentValuePath="ClassName" DependentValuePath="Score"/> </charting:Chart> And the property on the viewmodel: // NB: viewmodel derived from Josh Smith's BindableObject public class ExamResultsViewModel : BindableObject { // ... private ScoreDistributionByClass _scoreDistribution; public ScoreDistributionByClass ScoreDistribution { get { return _scoreDistribution; } set { if (_scoreDistribution == value) { return; } _scoreDistribution = value; RaisePropertyChanged(() => ScoreDistribution); } } However, when I update the ScoreDistribution property (by setting it to a new ScoreDistribution object), the chart gets an additional series (based on the new ScoreDistribution) as well as keeping the original series (based on the previous ScoreDistribution). To illustrate this, here are a couple of screenshots showing the chart before an update (with a single data point in ScoreDistribution.ClassScores) and after it (now with 3 data points in ScoreDistribution.ClassScores): Now, I realise there are other ways I could be doing this (e.g. changing the contents of the original ScoreDistribution object rather than replacing it entirely), but I don't understand why it's going wrong in its current form. Can anyone help?

    Read the article

  • How to handle ViewModel and Database in C#/WPF/MVVM App

    - by Mike B
    I have a task management program with a "Urgency" field. Valid values are Int16 currently mapped to 1 (High), 2 (Medium), 3 (Low), 4 (None) and 99 (Closed). The urgency field is used to rank tasks as well as alter the look of the items in the list and detail view. When a user is editing or adding a new task they select or view the urgency in a ComboBox. A Converter passes Strings to replace the Ints. The urgency collection is so simple I did not make it a table in the database, instead it is a, ObservableCollection(Int16) that is populated by a method. Since the same screen may be used to view a closed task the "Closed" urgency must be in the ItemsSource but I do not want the user to be able to select it. In order to prevent the user from being able to select that item in the ComboBox but still be able to see it if the item in the database has that value should I... Manually disable the item in the ComboBox in code or Xaml (I doubt it) Change the Urgency collection from an Int16 to an Object with a Selectable Property that the isEnabled property of the ComboBoxItem Binds to. Do as in 2 but also separate the urgency information into its own table in the database with a foreign key in the Tasks table None of the above (I suspect this is the correct answer) I ask this because this is a learning project (My first real WPF and first ever MVVM project). I know there is rarely one Right way to do something but I want to make sure I am learning in a reasonable manner since it if far harder to Unlearn bad habits Thanks Mike

    Read the article

  • Wpf: Why is WriteableBitmap getting slower?

    - by fritz
    There is a simple MSDN example about WriteableBitmap. It shows how to draw a freehand line with the cursor by just updating one pixel when the mouse is pressed and is moving over a WPF -Image Control. writeableBitmap.Lock(); (...set the writeableBitmap.BackBuffers pixel value...) writeableBitmap.AddDirtyRect(new Int32Rect(column, row, 1, 1)); writeableBitmap.Unlock(); Now I'm trying to understand the following behaviour when moving the mouse pointer very fast: If the image/bitmap size is relatively small e.g. 800:600 pixel, then the last drawn pixel is always "synchronized" with the mouse pointers position, i.e. there is no delay, very fast reaction on mouse movements. But if the bitmap gets larger e.g. 1300:1050 pixel, you can notice a delay, the last drawn pixel always appear a bit delayed behind the moving mouse pointer. So as in both cases only one pixel gets updated with "AddDirtyRect", the reaction speed should be independent from the bitmap size!? But it seems that Writeablebitmap gets slower when it's size gets larger. Or does the whole bitmap somehow get transferred to the graphic device on every writeableBitmap.Unlock(); call , and not only the rectangle area speficied in the AddDirtyRect method? fritz

    Read the article

  • WPF Repeater (like) control for collection source??

    - by Sonic Soul
    I have a WPF DataGrid bound to ObservableCollection. Each item in my collection has Property which is a List. In my row details pane, i would like to write out formatted textblocks for each item in this collection. The end result would be something equivalent to: <TextBlock Style="{StaticResource NBBOTextBlockStyle}" HorizontalAlignment="Right"> <TextBlock.Inlines> <Run FontWeight="Bold" Text="{Binding Path=Exchanges[0].Name}" /> <Run FontWeight="Bold" Text="{Binding Path=Exchanges[0].Price}" /> <LineBreak /> <Run Foreground="LightGray" Text="{Binding Path=Exchanges[0].Quantity}" /> </TextBlock.Inlines> </TextBlock> <TextBlock Style="{StaticResource NBBOTextBlockStyle}"> <TextBlock.Inlines> <Run FontWeight="Bold" Text="{Binding Path=Exchanges[1].Name}" /> <Run FontWeight="Bold" Text="{Binding Path=Exchanges[1].Price}" /> <LineBreak /> <Run Foreground="LightGray" Text="{Binding Path=Exchanges[1].Quantity}" /> </TextBlock.Inlines> </TextBlock> and so on 0-n times. I've tried using ItemsControl for this: <ItemsControl ItemsSource="{Binding Path=Exchanges}"> <DataTemplate> <Label>test</Label> </DataTemplate> </ItemsControl> however, this appears to be only meant for more static sources, as it throws the following exception (collection is not altered after creation): ItemsControl Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead Is there another way to achieve this?

    Read the article

  • Incorporating the Windows 7 onscreen keyboard into a WPF app

    - by mmr
    Windows 7 has a really nice onscreen keyboard program/control for touchscreens. I have a touchscreen app that was originally written for, and will be deployed on, XP. Is it possible to incorporate this keyboard directly into my app, rather than me using a custom control? I can find no programmatic information about it, so any links would be very helpful. Specifically, I'd need: To be able to use the keyboard on an XP machine that will have .NET 3.5 sp1 installed on it. To be able to hide the native keyboard on Windows 7, because I've already incorporated the touchscreen keyboard in my UI and so I don't need another one cluttering up the UI. This native keyboard has two attractive aspects to it. First off, it's automatically localized to the customer's language (though the rest of the app will need modification), and second off, it doesn't seem to suffer from 'touch lag' as the OS tries to figure out whether or not I'm doing a gesture, because I'm clearly typing on a keyboard. The app is WPF based, which should mean easy integration with Windows 7 based controls. EDIT: I'd really like the XP thing, but it's not a requirement. The ability to use the keyboard in Win7, though, seems like it should be possible and even the right way to do it.

    Read the article

  • WPF - Dynamic tooltip

    - by Al Mackenzie
    I have a class ToolTipProvider which has a method string GetToolTip(UIElement element) which will return a specific tooltip for the UIElement specified, based on various factors including properties of the UIElement itself and also looking up into documentation which can be changed dynamically. It will also probably run in a thread so when the form first fires up the tooltips will be something like the visual studio 'Document cache is still being constructed', then populated in the background. I want to allow this to be used in any wpf form with the minimum effort for the developer. Essentially I want to insert an ObjectDataProvider resource into the Window.Resources to wrap my ToolTipProvider object, then I think I need to create a tooltip (called e.g. MyToolTipProvider) in the resources which references that ObjectDataProvider, then on any element which requires this tooltip functionality it would just be a case of ToolTip="{StaticResource MyToolTipProvider}" however I can't work out a) how to bind the actual elemnt itself to the MethodParameters of the objectdataprovider, or b) how to force it to call the method each time the tooltip is opened. Any ideas/pointers on the general pattern I need? Not looking for complete solution, just any ideas from those more experienced

    Read the article

  • Styling columns based on DataGridTemplateColumn in a WPF DataGrid

    - by nareshbhatia
    I am using a WPF DataGrid where one of the columns has a requirement to show an "Edit" hyperlink if the row is editable - this is indicated by a boolean flag in the backing model for the row. I was able to achieve this using a DataGridTemplateColumn - no problems. However an additional requirement on the entire row is not to show any highlights when the row is selected (this is a blue background by default). I have been able to achieve this on other columns by defining the DataGridCell style with a transparent background, e.g. <DataGridTextColumn Header="Id" Binding="{Binding Path=Id}" HeaderStyle="{StaticResource DataGridColumnHeaderStyle}" CellStyle="{StaticResource DataGridCellStyle}" /> where DataGridCellStyle is defined as follows: <Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}"> <Setter Property="Background" Value="Transparent" /> ... </Style> However the column in question, a DataGridTemplateColumn, does not offer a "CellStyle" attribute which I can use for turning off selection highlights. So my question is how to set the cell style when using a DataGridTemplateColumn? Here's my implementation of the column which satisfies the first requirement (i.e. showing an "Edit" hyperlink if the row is editable): <DataGridTemplateColumn Header="Actions" HeaderStyle="{StaticResource CenterAlignedColumnHeaderStyle}"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Visibility="{Binding Path=Editable, Converter={StaticResource convVisibility}}" Style="{StaticResource CenterAlignedElementStyle}"> <Hyperlink Command="..." CommandParameter="{Binding}"> <TextBlock Text="Edit" /> </Hyperlink> </TextBlock> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> Thanks.

    Read the article

  • WPF Toolkit Charting and IndependentValueBinding, IndependentValuePath

    - by Joel Barsotti
    So I'm having a problem with the charting engine from the WPF toolkit. We haven't moved our data to a proper object model, so the ItemSource is backed with a DataView. First attempt <chartingToolkit:ScatterSeries x:Name="TargetSeries" DataPointStyle="{StaticResource TargetStyle}" ItemsSource="{Binding Path=TargetSeriesData}" IndependentValueBinding="{Binding Path=TargetSeries_X}" DependentValueBinding="{Binding Path=TargetSeries_X}" /> This crashes because, I believe, it thinks the bindings are the values to plot or some sort of mismatch. Second attempt <chartingToolkit:ScatterSeries x:Name="TargetSeries" DataPointStyle="{StaticResource TargetStyle}" ItemsSource="{Binding Path=TargetSeriesData}" IndependentValuePath="{Binding Path=TargetSeries_X}" DependentValuePath="{Binding Path=TargetSeries_X}" /> This crashes during the init step becaue the Path properties aren't backed with dependency properties and therefore cannot be bound. Third attempt <chartingToolkit:ScatterSeries x:Name="TargetSeries" DataPointStyle="{StaticResource TargetStyle}" ItemsSource="{Binding Path=TargetSeriesData}" IndependentValuePath="targetFooXColumnName" DependentValuePath="targetFooYColumnName" /> Now this works! But I wanted to use the binding so I can switch from using the targetFooXColumnName to the targetFooBarXColumnName. So this solution will cause a whole lot of hacky looking code to switch the Path's manually. Anyway to fix this? Can I use some sort of convertor to get the Binding properties to correctly pull the data from the columns in the DataView? Thanks, Joel

    Read the article

  • saving WPF InkCanvas to a JPG - image is getting cropped

    - by Jason
    I have a WPF InkCanvas control I'm using to capture a signature in my application. The control looks like this - it's 700x300 However, when I save it as a JPG, the resulting image looks like this, also 700x300 The code I'm using to save sigPath = System.IO.Path.GetTempFileName(); MemoryStream ms = new MemoryStream(); FileStream fs = new FileStream(sigPath, FileMode.Create); RenderTargetBitmap rtb = new RenderTargetBitmap((int)inkSig.Width, (int)inkSig.Height, 96d, 96d, PixelFormats.Default); rtb.Render(inkSig); JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(rtb)); encoder.Save(fs); fs.Close(); This is the XAML I'm using: <Window x:Class="Consent.Client.SigPanel" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="Transparent" Topmost="True" AllowsTransparency="True" Title="SigPanel" Left="0" Top="0" Height="1024" Width="768" WindowStyle ="None" ShowInTaskbar="False" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" > <Border BorderThickness="1" BorderBrush="Black" Background='#FFFFFFFF' x:Name='DocumentRoot' Width='750' Height='400' CornerRadius='10'> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> <TextBlock Name="txtLabel" FontSize="24" HorizontalAlignment="Center" >Label</TextBlock> <InkCanvas Opacity="1" Background="Beige" Name="inkSig" Width="700" Height="300" /> <StackPanel HorizontalAlignment="Center" Orientation="Horizontal"> <Button FontSize="24" Margin="10" Width="150" Name="btnSave" Click="btnSave_Click">Save</Button> <Button FontSize="24" Margin="10" Width="150" Name="btnCancel" Click="btnCancel_Click">Cancel</Button> <Button FontSize="24" Margin="10" Width="150" Name="btnClear" Click="btnClear_Click">Clear</Button> </StackPanel> </StackPanel> </Border> In the past this worked perfectly. I can't figure out what changed that is causing the image to shift when it is saved.

    Read the article

  • WPF MVVM Picklist Example

    - by Tim
    Hi, I am looking for a way of easily maintaining a list of Users belonging to a particular Group. I have thought about using a Picklist, where I have 2 listboxs, the first contains a list of Users the second a list of Users belonging to the Group. There will be buttons to allow the adding and removing of selected Users from the Group. As users are added they move from the left listbox to the right, as they are removed they are move from the right to the list. This is pretty common situation. Do you know of any examples of doing this in WPF using the MVVM pattern? I am having difficulty understand how the binding may work to my View Model and Business Entities. Especially persisting the data back to the database. I am using stored procedure calls to do the CRUD logic, so I need to keep a list of which Users had been removed so I can delete them. Is this the best way to perform this functionality or is there a better way. I simply want to pick from a list (the list may be large).

    Read the article

  • Wpf Mvvm ComboBox

    - by 2Fast4YouBR
    Hi All, I am new in the Wpf world, so I created a couple of views and all of them have at least one ComboBox, as I am using the MvvM pattern, I get my self re-typing all the time the same line of codes to fill the Combo and to get the SelectedItem (creating properties, privates for fill and other to get). Is there some kind of framework that can improve this part ? or hack/trick ??? as I see too much repetitive code... maybe I am doing something wrong, take a look: XAML: <ComboBox name= "cbDepartments" DisplayMemberPath="DepartmentName" SelectedValuePath ="PrimaryKey" ItemsSource="{Binding Path=Departments}" SelectedItem="{Binding Path=DefaultBranch,Mode=TwoWay}" > ViewModel: private Department defaultBranch; public Department DefaultBranch { get { return this.defaultBranch; } set { if (this.defaultBranch != value) { this.defaultBranch = value; this.OnPropertyChanged("DefaultBranch"); this.saveChangeCommand.RaiseCanExecuteChanged(); this.UserMessage = string.Empty; } } } private ObservableCollection<Department> departments; public ObservableCollection<Department> Departments { get { return this.departments; } set { if (this. departments!= value) { this. departments = value; this.OnPropertyChanged("Departments"); } } }

    Read the article

  • How to toggle a WPF Grid column visibility

    - by serialhobbyist
    I'm having some trouble getting this to work in a WPF app I'm working on. Basically, what I'm after is something like the Task pane in an MMC: The app has three columns in the main part of the display. I need a column on the right side which is resizable. I presume this means using a Grid with a GridSplitter but anything that works will do. I want to be able to save the width of the right-side column when the app is closed and load it when the app is opened but this should be an initial size: the user should be able to resize it. When I resize the window, I want the left- and right-side columns to stay the same size and the middle column to resize with the window width. The left- and right-side columns need to have a minimum width. When I resize the right-side column I want the centre column to get smaller but not the left-side column. I also want to be able to toggle the visibility of the right-side column with a toggle button which is outside the column and when it returns to visibility I want it to be the same width it was before. I'm trying to do as much as possible in XAML and with binding. And can I have it topped with cream, ice cream and chocolate chips, please? :-)

    Read the article

  • XAML to HTML Conversion - WPF RichTextBox

    - by Erika
    I have the problem where i have a WPF RichTextBox, and i'm extracting its XAML code and saving it to a txt file. When i copy paste the XAML code generated to a XAMLtoHTML converter like this http://blogs.msdn.com/wpfsdk/archive/2006/05/25/606317.aspx , some error must be occuring as i'm always getting a blank result! If i write test in the RichTextBox i get the following XAML: <Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Left" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us" FlowDirection="LeftToRight" NumberSubstitution.CultureSource="Text" NumberSubstitution.Substitution="AsCulture" FontFamily="Segoe UI" FontStyle="Normal" FontWeight="Normal" FontStretch="Normal" FontSize="12" Foreground="#FF000000" Typography.StandardLigatures="True" Typography.ContextualLigatures="True" Typography.DiscretionaryLigatures="False" Typography.HistoricalLigatures="False" Typography.AnnotationAlternates="0" Typography.ContextualAlternates="True" Typography.HistoricalForms="False" Typography.Kerning="True" Typography.CapitalSpacing="False" Typography.CaseSensitiveForms="False" Typography.StylisticSet1="False" Typography.StylisticSet2="False" Typography.StylisticSet3="False" Typography.StylisticSet4="False" Typography.StylisticSet5="False" Typography.StylisticSet6="False" Typography.StylisticSet7="False" Typography.StylisticSet8="False" Typography.StylisticSet9="False" Typography.StylisticSet10="False" Typography.StylisticSet11="False" Typography.StylisticSet12="False" Typography.StylisticSet13="False" Typography.StylisticSet14="False" Typography.StylisticSet15="False" Typography.StylisticSet16="False" Typography.StylisticSet17="False" Typography.StylisticSet18="False" Typography.StylisticSet19="False" Typography.StylisticSet20="False" Typography.Fraction="Normal" Typography.SlashedZero="False" Typography.MathematicalGreek="False" Typography.EastAsianExpertForms="False" Typography.Variants="Normal" Typography.Capitals="Normal" Typography.NumeralStyle="Normal" Typography.NumeralAlignment="Normal" Typography.EastAsianWidths="Normal" Typography.EastAsianLanguage="Normal" Typography.StandardSwashes="0" Typography.ContextualSwashes="0" Typography.StylisticAlternates="0"><Paragraph><Run>test</Run></Paragraph></Section> pleaseee help!! Any Ideas?

    Read the article

  • WPF Exposing a calculated property for binding (as DependencyProperty)

    - by kubal5003
    Hello, I have a complex WPF control that for some reasons (ie. performance) is not using dependency properties but simple C# properties (at least at the top level these are exposed as properties). The goal is to make it possible to bind to some of those top level properties - I guess I should declare them as DPs.(right? or is there some other way to achieve this? ) I started reading on MSDN about DependencyProperties and DependencyObjects and found an example: public class MyStateControl : ButtonBase { public MyStateControl() : base() { } public Boolean State { get { return (Boolean)this.GetValue(StateProperty); } set { this.SetValue(StateProperty, value); } } public static readonly DependencyProperty StateProperty = DependencyProperty.Register( "State", typeof(Boolean), typeof(MyStateControl),new PropertyMetadata(false)); } If I'm right - this code enforces the property to be backed up by DependencyProperty which restricts it to be a simple property with a store(from functional point of view, not technically) instead of being able to calculate the property value each time getter is called and setting other properties/fields each time setter is called. What can I do about that? Is there any way I could make those two worlds meet at some point?

    Read the article

  • WPF resource merged to Application.Resources but not resolved at runtime

    - by arconaut
    I have a brush that is part of a ResourceDictionary that is merged to Application.Resources. But for some reason it's not resolved at runtime when a style is being applied to one of the controls. However, if I call Application.Current.FindResource("BrushName") from the Immediate Window at the time when exception is thrown, the resource is found. Am I missing something? Isn't WPF supposed to try to look for the resource in the app's resources? UPDATE The application is quite big, so I can't post all actual code but here's the way the resources are merged and used: Brushes.xaml <ResourceDictionary ...> <SolidColorBrush x:Key="BrushName" Color="#12345678" /> <\ResourceDictionary> SomeStyles.xaml <ResourceDictionary ...> <Style x:Key="SomeStyle"> <Setter Property="SomeProperty" Value="{StaticResource BrushName}" /> </Style> </ResourceDictionary> App.xaml <Application ...> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Brushes.xaml" /> <ResourceDictionary Source="SomeStyles.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application ...> And then some control might use the style using the resource like this: ... Style={StaticResource SomeStyle} ...

    Read the article

  • Setting WPF RichTextBox width and height according to the size of a monospace font

    - by oxeb
    I am trying to fit a WPF RichTextBox to exactly accommodate a grid of characters in a particular monospace font. I am currently using FormattedText to determine the width and height of my RichTextBox, but the measurements it is providing me with are too small--specifically two characters in width too small. Is there a better way to perform this task? This does not seem to be an appropriate way to determine the size of my control. RichTextBox rtb; rtb = new RichTextBox(); FontFamily fontFamily = new FontFamily("Consolas"); double fontSize = 16; char standardizationCharacter = 'X'; String standardizationLine = ""; for(long loop = 0; loop < columns; loop ++) { standardizationLine += standardizationCharacter; } standardizationLine += Environment.NewLine; String standardizationString = ""; for(long loop = 0; loop < rows; loop ++) { standardizationString += standardizationLine; } Typeface typeface = new Typeface(fontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); FormattedText formattedText = new FormattedText(standardizationString, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, fontSize, Brushes.Black); rtb.Width = formattedText.Width; rtb.Height = formattedText.Height;

    Read the article

  • WPF UI Automation - AutomationElement.FindFirst fails when there are lots of elements

    - by Orion Edwards
    We've got some automated UI tests for our WPF app (.NET 4); these test use the UI Automation API's. We call AutomationElement.FindFirst to find a target element, and then interact with it. Example (pseudocode): var nameEquals = new PropertyCondition(AutomationElement.NameProperty, "OurAppWindow"); var appWindow = DesktopWindow.FindFirst(TreeScope.Children, nameEquals); // this succeeds var idEquals = new PropertyCondition(AutomationElement.AutomationIdProperty, "ControlId"); var someItem = appWindow.FindFirst(TreeScope.Descendants, idEquals); // this suceeds sometimes, and fails sometimes! The problem is, the appWindow.FindFirst will sometimes fail and return null, even when the element is present. I've written a helper function which walks the UI automation tree manually and prints it out, and the element with the correct ID is present in all cases. It seems to be related to how many other items are also being displayed in the window. If there are no other items then it always succeeds, but when there are many other complex UI elements being displayed alongside it, then the find fails. I can't find any documented element limit mentioned for any of the automation API's - is there some way around this? I'm thinking I might have to write my own implemententation of FindFirst which does the tree walk manually itself... As far as I can tell this should work, because my tree-printer utility function does exactly that, and it's ok, but it seems like this would be unnecessary and slow :-( Any help would be greatly appreciated

    Read the article

  • Wrapped WPF Control

    - by Robert
    Hi, I'm trying to create a GUI (WPF) Library where each (custom) control basically wraps an internal (third party) control. Then, I'm manually exposing each property (not all of them, but almost). In XAML the resulting control is pretty straightforward: <my:CustomButton Content="ClickMe" /> And the code behind is quite simple as well: public class CustomButton : Control { private MyThirdPartyButton _button = null; static CustomButton() { DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomButton), new FrameworkPropertyMetadata(typeof(CustomButton))); } public CustomButton() { _button = new MyThirdPartyButton(); this.AddVisualChild(_button); } protected override int VisualChildrenCount { get { return _button == null ? 0 : 1; } } protected override Visual GetVisualChild(int index) { if (_button == null) { throw new ArgumentOutOfRangeException(); } return _button; } #region Property: Content public Object Content { get { return GetValue(ContentProperty); } set { SetValue(ContentProperty, value); } } public static readonly DependencyProperty ContentProperty = DependencyProperty.Register( "Content", typeof(Object), typeof(CustomButton), new FrameworkPropertyMetadata(new PropertyChangedCallback(ChangeContent)) ); private static void ChangeContent(DependencyObject source, DependencyPropertyChangedEventArgs e) { (source as CustomButton).UpdateContent(e.NewValue); } private void UpdateContent(Object sel) { _button.Content = sel; } #endregion } The problem comes after we expose MyThirdPartyButton as a property (in case we don't expose something, we would like to give the programmer the means to use it directly). By simply creating the property, like this: public MyThirdPartyButton InternalControl { get { return _button; } set { if (_button != value) { this.RemoveVisualChild(_button); _button = value; this.AddVisualChild(_button); } } } The resulting XAML would be this: <my:CustomButton> <my:CustomButton.InternalControl> <thirdparty:MyThirdPartyButton Content="ClickMe" /> </my:CustomButton.InternalControl> And what I'm looking for, is something like this: <my:CustomButton> <my:CustomButton.InternalControl Content="ClickMe" /> But (with the code I have) its impossible to add attributes to InternalControl... Any ideas/suggestions? Thanks a lot, -- Robert

    Read the article

  • WPF MVVM ViewModel constructor designmode

    - by Snake
    Right, I've got a main wpf window: <Window x:Class="NorthwindInterface.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ViewModels="clr-namespace:NorthwindInterface.ViewModels" Title="MainWindow" Height="350" Width="525"> <Window.DataContext> <ViewModels:MainViewModel /> </Window.DataContext> <ListView ItemsSource="{Binding Path=Customers}"> </ListView> </Window> And the MainViewModel is this: class MainViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged = delegate { }; public MainViewModel() { Console.WriteLine("test"); using (NorthwindEntities northwindEntities = new NorthwindEntities()) { this.Customers = (from c in northwindEntities.Customers select c).ToList(); } } public List<Customer> Customers { get;private set; } Now the problem is that in designermode I can't see my MainViewModel, it highlights it saying that it can't create an instance of the MainViewModel. It is connecting to a database. That is why (when I comment the code the problem is solved). But I don't want that. Any solutions on best practices around this?

    Read the article

< Previous Page | 44 45 46 47 48 49 50 51 52 53 54 55  | Next Page >