@@ -221,9 +221,14 @@ bool CtrlSpace(ITextEditor editor, XamlCompletionContext context)
221221 // DO NOT USE generator.CreateListForContext here!!! results in endless recursion!!!!
222222 if ( context . Attribute != null ) {
223223 if ( ! DoMarkupExtensionCompletion ( context ) ) {
224- var completionList = new XamlCompletionItemList ( context ) ;
225- completionList . PreselectionLength = editor . GetWordBeforeCaretExtended ( ) . Length ;
226- if ( ( context . ActiveElement . Name == "Setter" || context . ActiveElement . Name == "EventSetter" ) && ( context . Attribute . Name == "Property" || context . Attribute . Name == "Value" ) ) {
224+ XamlCompletionItemList completionList = new XamlCompletionItemList ( context ) ;
225+ string starter = editor . GetWordBeforeCaretExtended ( ) ;
226+ if ( starter . Contains ( "." ) ) {
227+ completionList . PreselectionLength = starter . Length - starter . IndexOf ( '.' ) - 1 ;
228+ } else {
229+ completionList . PreselectionLength = starter . Length ;
230+ }
231+ if ( ( new [ ] { "Setter" , "EventSetter" } . Any ( item => context . ActiveElement . Name == item ) ) && ( new [ ] { "Property" , "Value" , "Event" , "Handler" } . Any ( item => context . Attribute . Name == item ) ) ) {
227232 DoSetterAndEventSetterCompletion ( context , completionList ) ;
228233 editor . ShowCompletionWindow ( completionList ) ;
229234 } else if ( ( context . ActiveElement . Name . EndsWith ( "Trigger" , StringComparison . Ordinal ) || context . ActiveElement . Name == "Condition" ) && context . Attribute . Name == "Value" ) {
@@ -239,7 +244,8 @@ bool CtrlSpace(ITextEditor editor, XamlCompletionContext context)
239244 return false ;
240245 }
241246
242- void DoTriggerCompletion ( XamlCompletionContext context , XamlCompletionItemList completionList ) {
247+ void DoTriggerCompletion ( XamlCompletionContext context , XamlCompletionItemList completionList )
248+ {
243249 bool isExplicit ;
244250 AttributeValue value = MarkupExtensionParser . ParseValue ( Utils . LookForTargetTypeValue ( context , out isExplicit , "Trigger" ) ?? string . Empty ) ;
245251 string typeNameString ;
@@ -273,13 +279,13 @@ void DoTriggerCompletion(XamlCompletionContext context, XamlCompletionItemList c
273279 }
274280 }
275281
276- void DoSetterAndEventSetterCompletion ( XamlCompletionContext context , XamlCompletionItemList completionList ) {
277- bool isExplicit ;
278- string element = context . ParentElement . Name . EndsWith ( "Trigger" , StringComparison . Ordinal ) ? "Trigger" : context . ParentElement . Name ;
279- AttributeValue value = MarkupExtensionParser . ParseValue ( Utils . LookForTargetTypeValue ( context , out isExplicit , element ) ?? string . Empty ) ;
282+ void DoSetterAndEventSetterCompletion ( XamlCompletionContext context , XamlCompletionItemList completionList )
283+ {
280284 string typeNameString ;
281- var rr = resolver . ResolveAttributeValue ( context , value , out typeNameString ) ;
282- IType typeName = rr . Type ;
285+ int dotIndex ;
286+ IType typeName = ResolveTargetType ( context , out typeNameString , out dotIndex ,
287+ string . Equals ( context . Attribute . Name , "Property" )
288+ || string . Equals ( context . Attribute . Name , "Event" ) ) ;
283289
284290 MemberResolveResult mrr ;
285291 switch ( context . Attribute . Name ) {
@@ -311,13 +317,23 @@ void DoSetterAndEventSetterCompletion(XamlCompletionContext context, XamlComplet
311317 . Where ( p => p . IsPublic && p . CanSet )
312318 . Select ( prop => new XamlCompletionItem ( prop ) )
313319 ) ;
320+ if ( dotIndex == - 1 ) {
321+ completionList . Items . AddRange (
322+ generator . GetTypesForPropEventNameCompletion ( context , true )
323+ ) ;
324+ }
314325 break ;
315326 case "Event" :
316327 completionList . Items . AddRange (
317328 typeName . GetEvents ( )
318329 . Where ( e => e . IsPublic )
319330 . Select ( evt => new XamlCompletionItem ( evt ) )
320331 ) ;
332+ if ( dotIndex == - 1 ) {
333+ completionList . Items . AddRange (
334+ generator . GetTypesForPropEventNameCompletion ( context , true )
335+ ) ;
336+ }
321337 break ;
322338 case "Handler" :
323339 var loc3 = context . Editor . Document . GetLocation ( XmlParser . GetActiveElementStartIndex ( context . Editor . Document . Text , context . Editor . Caret . Offset ) ) ;
@@ -340,6 +356,28 @@ void DoSetterAndEventSetterCompletion(XamlCompletionContext context, XamlComplet
340356 }
341357 }
342358
359+ IType ResolveTargetType ( XamlCompletionContext context , out string typeName , out int dotIndex , bool isPropertyOrEventName = false )
360+ {
361+ string targetTypeValue ;
362+ dotIndex = - 1 ;
363+ if ( isPropertyOrEventName && context . AttributeValue . IsString ) {
364+ dotIndex = context . AttributeValue . StringValue . IndexOf ( '.' ) ;
365+ }
366+ if ( dotIndex > 0 ) {
367+ targetTypeValue = context . AttributeValue . StringValue . Substring ( 0 , dotIndex ) ;
368+ } else {
369+ string element ;
370+ bool isExplicit ;
371+ if ( context . ParentElement . Name . EndsWith ( "Trigger" , StringComparison . Ordinal ) )
372+ element = "Trigger" ;
373+ else
374+ element = context . ParentElement . Name ;
375+ targetTypeValue = Utils . LookForTargetTypeValue ( context , out isExplicit , element ) ;
376+ }
377+ AttributeValue value = MarkupExtensionParser . ParseValue ( targetTypeValue ?? string . Empty ) ;
378+ return resolver . ResolveAttributeValue ( context , value , out typeName ) . Type ;
379+ }
380+
343381 bool DoAttributeCompletion ( XamlCompletionContext context , XamlCompletionItemList completionList )
344382 {
345383 XamlAstResolver resolver = new XamlAstResolver ( compilation , context . ParseInformation ) ;
0 commit comments